|
|
| Add to Favorites.. |
Share it.. |
IE user Click Here Fx user press ctrl + D |
|
|
CODE Information:
|
|
Date difference calculation |
|
| Author: , Date added:14th August 2007 |
| Total Hits:688, User Rating:0 |
|
Script to calculate the difference between 2 given timestamps.
|
|
|
|
Sample INPUT and OUTPUT:
<?php $from = mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')); //just adding 2 hours and 30minutes with the present time $to = mktime(date('H')+2, date('i')+30, date('s'), date('m'), date('d'), date('Y')); echo datediff($from, $to); ?>
|
CODE:
<?php function datediff($from, $to) { $datediff = $to-$from; if ($datediff <= 60) { $datediff .= ($datediff == 1)?"Second": " Seconds"; } elseif($datediff <= 3600) { $minutes = (($minute = floor($datediff/60)) > 1)?$minute." Minutes ": $minute." Minute "; $seconds = (($second = floor(($datediff-($minute * 60)))) > 1)?$second." Seconds ": $second." Second "; $datediff = $minutes." ".$seconds; } else { $hours = (($hour = floor($datediff/3600)) > 1)?$hour." Hours ": $hour." Hour "; $minutes = (($minute = floor(($datediff-($hour * 3600))/60)) > 1)?$minute." Minutes ": $minute." Minute "; $datediff = $days.' '.$hours." ".$minutes; } return $datediff; } ?>
|
|
DATE and TIME |
|
|
Date difference calculation |
( View Code )
|
| Author: , Date added:14th August 2007 |
| Total Hits:688, User Rating:0 |
|
Script to calculate the difference between 2 given timestamps.
|
|
|
| |
|
|
|