Return to Snippet

Revision: 43117
at March 17, 2011 04:00 by dsoms


Initial Code
$date1 = "2008-03-15";
$date2 = "2011-03-16";

$diff = abs(strtotime($date2) - strtotime($date1));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

printf("%d years, %d months, %d days\n", $years, $months, $days);

Initial URL

                                

Initial Description

                                

Initial Title
Calculate the difference between two dates

Initial Tags
php

Initial Language
PHP