PHP time difference function

Source: Internet
Author: User

// Calculate the number of days from January 1, January 1, a.m., $ mm, and $ dd. <br/> function datelocal ($ yyyy, $ mm, $ dd) {<br/> $ monthdays = array (, 28, 31 ); // The number of days of a month in a non-leap year <br/> // determines whether the value is a leapyear. The leapyear value is 1, otherwise $ leapyear = 0 <br/> if ($ YY % 4 = 0 & $ yyyy % 100! = 0 | $ yyyy % 400 = 0) <br/> $ leapyear = 1; <br/> else <br/> $ leapyear = 0; <br/> // calculate the number of days from January 1, a.m.: days per year + days per month + days per day <br/> $ days = ($ yyyy-1) * 365 + floor ($ yyyy-1)/4)-floor ($ yyyy-1)/100) + floor ($ yyyy-1)/400 ); <br/> for ($ I = 1; $ I <= $ mm; $ I ++) {<br/> $ days + = $ monthdays [$ I-2]; <br/> if ($ leapyear = 1 & $ I = 3) // the year in which the month belongs is a leap year, and the month exceeds February: 28 days + 1 day <br/> $ days + = 1; <br/>}< br/> $ days + = $ DD-1; <br/> return $ days; <br/>}< br/> // calculate $ yyyy2-$ mm2-$ dd2, $ yyyy1-$ MM1-$ DD1 difference days <br/> function datediff ($ yyyy2, $ mm2, $ dd2, $ yyyy1, $ MM1, $ DD1) {<br/> $ daysdiff = ABS (datelocal ($ yyyy2, $ mm2, $ dd2)-datelocal ($ yyyy1, $ MM1, $ DD1 )); <br/> return $ daysdiff; <br/>}< br/> echo datediff );

 

From: http://www.drulanz.com/website-build/lamp/phpdaysdiff/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.