Sunday, February 10, 2013

two date difference in php

$olddate = "2010-03-24";
$currentdate = date('Y-m-d');

$diff = abs(strtotime($currentdate) - strtotime($olddate));

$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);

No comments:

Post a Comment