: This article describes how many years, months, and days are separated by two dates in php. For more information about PHP tutorials, see. The first method is implemented using the PHP class library.
/*** Function: calculate the number of years, months, and days between two dates. * param string $ date1 [Format: 2011-11-5] * param string $ date2 [format: 2012-12-01] * return array ('year', 'month', 'day'); */function diffDate ($ date1, $ date2) {$ datetime1 = new \ DateTime ($ date1); $ datetime2 = new \ DateTime ($ date2); $ interval = $ datetime1-> diff ($ datetime2 ); $ time ['Y'] = $ interval-> format ('% Y'); $ time ['M'] = $ interval-> format (' % M '); $ time ['D'] = $ interval-> format ('% d'); $ time ['H'] = $ interval-> format (' % h '); $ time ['I'] = $ interval-> format ('% I'); $ time ['s'] = $ interval-> format ('% s '); $ time ['A'] = $ interval-> format ('% A'); // returns $ time for the total days of two time differences ;} # use instance $ sss = diffDate ('2017-12-25 12:30:30 ', '2017-12-26 15:00:00'); print_r ($ sss ); # output Array ([y] => 00 [m] => 0 [d] => 1 [h] => 02 [I] => 29 [s] => 30 [a] => 1)
The second method is implemented using the function (still being tested ....)
// Calculate the difference between the two time ranges (hour, minute, and second) $ aaa = strtotime ('2017-12-26 16:33:33 '); $ bbb = $ aaa-time (); echo gmstrftime ('% Y % m % d % H: % M: % s', $ aaa); exit; $ left_time = 86400-time () + strtotime ($ orderInfo ['create _ time']); echo: gmstrftime ('% H: % M: % s', $ left_time );
The preceding section describes how many years, months, and days are separated by two dates in php computing, including related content. I hope my friends who are interested in the PHP Tutorial will be helpful.