Monday, 26 October 2015

PHP : 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..

writer : Sya Ahmad

0 comments:

Post a Comment