PHP Date Operations Summary
Recently the application of PHP date processing more, by the way record.
?
2011-07-04 * [1] = 2011-07-10 *) *///--------------------------------------Split line-------------------------------// PHP gets the first and last day of the month on which the specified date function getmonthday ($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 obtains two date interval days [PHP version >= 5.3 valid]function getintervalday ($date 1 = null, $date 2 = null) {$datetime 1 = new DateTime ($date 1); $datetime 2 = new DateTime ($date 2), $interval = $datetime 1->diff ($datetime 2), return $interval->format ('%a ');} function GetIntervalDay1 ($date 1 = null, $date 2 = null) {$datetime 1 = date_create ($date 1); $datetime 2 = Date_create ($date 2) ; $interval = Date_diff ($datetime 1, $datetime 2); return $interval->format ('%a ');} echo getintervalday (' 2011-07-25 ', ' 2011-07-26 ');//1echo getIntervalDay1 (' 2011-07-25 ', ' 2011-08-28 ');//34?>
??
?