Monday, May 23, 2011

Calculating differences between two date in months and days

<?php
$date1 = $TPC_From;
$date2 = $TPC_To;
$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 bulan, %d hari\n", $months, $days);  ?>

You can customize the code using your own purposes..

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...