Take the 2-minute tour ×

This question already has an answer here:

I am new here and php i want to know how to calculate date difference in php.
My date is mktime() formate.

Please confirm this is current issue for me.

share|improve this question

marked as duplicate by animuson, Kate Gregory, Antony, Frank van Puffelen, Hanlet Escaño Jun 23 '13 at 6:33


2 Answers 2

PHP has the function date_diff, which computes the date difference. See: http://php.net/manual/en/function.date-diff.php

share|improve this answer

In PHP to calculate the difference in two dates, you have to use mktime() function and then find out the difference in seconds.

Sample Code :

$epoch_1 = mktime(19,32,56,5,10,1965);

$epoch_2 = mktime(4,29,11,11,20,1962);

$diff_seconds  = $epoch_1 - $epoch_2;
$diff_weeks    = floor($diff_seconds/604800);
$diff_seconds -= $diff_weeks   * 604800;
$diff_days     = floor($diff_seconds/86400);
$diff_seconds -= $diff_days    * 86400;
$diff_hours    = floor($diff_seconds/3600);
$diff_seconds -= $diff_hours   * 3600;
$diff_minutes  = floor($diff_seconds/60);
$diff_seconds -= $diff_minutes * 60;

print "The two dates have $diff_weeks weeks, $diff_days days, ";
print "$diff_hours hours, $diff_minutes minutes, and $diff_seconds ";
print "seconds elapsed between them.";
share|improve this answer
Thank you so much ..........very great idea boss given by you. –  Alok Ranjan Mar 25 '11 at 11:51
