Common date functions in php [date addition and subtraction, difference between two dates, date conversion time cut] common date functions in php [date addition and subtraction, difference between two dates, date conversion time cut]
Script ec (2); script
The following code is a common date processing function, which can be used to add or subtract two dates, the difference between two dates, and the date conversion time cut.
Echo date ('Y-m-d', strtotime ('+ 1 d', strtotime ('1970-07-08'); // date plus Functions
Echo date ("Y-m-d", '20140901 ');
Echo'
';
Echo date ("Y-m-d", '20140901 ');
Die ();
$ D = "10:19:00 ";
Echo date ("Y-m-d", strtotime ("$ d + 1 day"); // date plus days function
Function dateToTime ($ d) // converts a date to a time heap
{
$ Year = (int) substr ("$ d",); // obtain the year
$ Month = (int) substr ("$ d", 5, 2); // obtain the month
$ Day = (int) substr ("$ d", 8, 2); // obtain the number of digits
Return mktime (0, 0, 0, $ month, $ day, $ year );
}
/*
The following function calculates two dates
*/
$ Date_1 = "2009-07-08 ";
Echo $ Date_1 + 1;
$ Date_2 = "2009-06-08 ";
$ Date_List_a1 = explode ("-", $ Date_1 );
$ Date_List_a2 = explode ("-", $ Date_2 );
$ D1 = mktime (0, 0, 0, $ Date_List_a1 [1], $ Date_List_a1 [2], $ Date_List_a1 [0]);
$ D2 = mktime (0, 0, 0, $ Date_List_a2 [1], $ Date_List_a2 [2], $ Date_List_a2 [0]);
$ Days = round ($ d1-$ d2)/3600/24 );
Echo "The difference between the two dates is $ Days ";
Original site reprinted from www.111cn.net/phper/php.html