# Calculating the difference between two dates : mktime « Date « PHP

Calculating the difference between two dates

```
<?php
\$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.";
?>

```

### Related examples in the same category

 1 Checking credit card expiration 2 Creating a Timestamp with mktime() 3 Use mktime to create a time 4 Using mktime() and date() 5 int mktime ( [int hour [, int minute [, int second [, int month[, int day [, int year [, int is_dst]]]]]]] ) 6 mktime() produces a GMT timestamp. 7 mktime.php 8 Making an epoch timestamp 9 Get the labor day