DateTime, diff in PHP

Source: Internet
Author: User

  

Manual Address: http://php.net/manual/en/dateinterval.format.php

1 $january=NewDateTime (' 2010-01-01 ');2 $february=NewDateTime (' 2010-02-01 ');3 $interval=$january->diff ($february);4 5 //%a would output the total number of days.6 Echo $interval->format ('%r%a total days '). ' <br/> ';//+31 Total Days7 8 //While%d would only output the number of already covered by the9 //month.Ten Echo $interval->format ('%m month,%d days ');//1 month, 0 days

Format formatting parameters:

The following characters is recognized in the format parameter string. Each format character must is prefixed by a percent sign ( %).
format character Description Example values
% Literal % %
Y Years, numeric, at least 2 digits with leading 0 in the
Y Years, numeric 1, 3
M Months, numeric, at least 2 digits with leading 0 A.
M Months, numeric 1, 3,
D Days, numeric, @ least 2 digits with leading 0 A.
D Days, numeric 1, 3,
A Total number of days as a result of a DateTime::d iff () or (unknown)otherwise 4, 8123
H Hours, numeric, at least 2 digits with leading 0 A.
H Hours, numeric 1, 3,
I Minutes, numeric, at least 2 digits with leading 0 on the other.
I Minutes, numeric 1, 3,
S Seconds, numeric, at least 2 digits with leading 0 A.
S Seconds, numeric 1, 3,
R Sign "-" when negative, "+" when positive -+
R Sign "-" when negative, empty when positive -,

DateTime, diff in PHP

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.