PHP date operation summary

Source: Internet
Author: User
PHP date operation summary recently, PHP date processing has been applied in many projects, which can be recorded by the way .? & Lt ;? Php // PHP obtain the echodate ('Y-m-D', time ()-86400) of the day before and after the current date; echodate ('Y-m-D ', time () + 86400) PHP date operation summary

There are many PHP date processing applications in recent projects, which should be recorded by the way.

?

 * [1] => 2011-07-10 *) * // Shard line ------------------------------------- // PHP obtains the function getMonthDay ($ date) on the first and last days of the month of the specified date) {$ firstday = date ("Y-m-01", strtotime ($ date); $ lastday = date ("Y-m-d ", strtotime ("$ firstday + 1 month-1 day"); return array ($ firstday, $ lastday);} print_r (getMonthDay ("2011-07-10 ")); /*** Array * (* [0] => 2011-07-01 * [1] => 2011-07-31 *)*/
// PHP returns the two-date interval days [PHP version> = 5.3 Valid] function getIntervalDay ($ date1 = null, $ date2 = null) {$ datetime1 = new DateTime ($ date1 ); $ datetime2 = new DateTime ($ date2); $ interval = $ datetime1-> diff ($ datetime2); return $ interval-> format ('% ');} function getIntervalDay1 ($ date1 = null, $ date2 = null) {$ datetime1 = date_create ($ date1); $ datetime2 = date_create ($ date2); $ interval = date_diff ($ datetime1, $ datetime2); return $ I Nterval-> format ('% A');} echo getIntervalDay ('2017-07-25', '2017-07-26 '); // 1 echo getIntervalDay1 ('2017-07-25 ', '2017-08-28 '); // 34?>
??

?

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.