There are two dates, how to determine the methods of php from one date to another in hours of days and months. I think a very common problem, tell me the algorithm.
I tried it myself through mktime - I got confused
There are two dates, how to determine the methods of php from one date to another in hours of days and months. I think a very common problem, tell me the algorithm.
I tried it myself through mktime - I got confused
$date = new DateTime("2012-12-21"); $interval = $date->diff(new DateTime("now")); echo $interval->format(($interval->invert ? "Осталось" : "Прошло")." лет: %y; месяцев: %m; дней: %d; часов: %h; минут: %i; секунд: %s");
$start = '12 02 12'; $end = '18 02 12'; $startExp = explode(' ', $start); $endExp = explode(' ', $end); $startTS = mktime(0, 0, 0, $startExp[1], $startExp[0], $startExp[2]); // timestamp начала $endTS = mktime(0, 0, 0, $endExp[1], $endExp[0], $endExp[2]); // timestamp конца var_dump($startTS, $endTS);
Next yourself.
function getTimeDifference($cur_time, $time) { $difference = abs($time – $cur_time); $return['days'] = floor($difference / 86400); $return['hours'] = floor($difference / 3600) % 24; $return['minutes'] = floor($difference / 60) % 60; return $return; }
Testing function:
print_r(getTimeDifference(1242902278, 1242803038));
Source: https://ru.stackoverflow.com/questions/94498/
All Articles