note 98120 added to function.date-diff
| From: | FlavioTubino at osu1 dot php dot net | Date: | Thu, 27 May 2010 00:37:51 +0000 |
| Subject: | note 98120 added to function.date-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169640@lists.php.net to get a copy of this message | ||
This is a very simple function to calculate the difference between two datetime values, returning
the result in seconds. To convert to minutes, just divide the result by 60. In hours, by 3600 and so
on.
Enjoy.
<?php
function time_diff($dt1,$dt2){
$y1 = substr($dt1,0,4);
$m1 = substr($dt1,5,2);
$d1 = substr($dt1,8,2);
$h1 = substr($dt1,11,2);
$i1 = substr($dt1,14,2);
$s1 = substr($dt1,17,2);
$y2 = substr($dt2,0,4);
$m2 = substr($dt2,5,2);
$d2 = substr($dt2,8,2);
$h2 = substr($dt2,11,2);
$i2 = substr($dt2,14,2);
$s2 = substr($dt2,17,2);
$r1=date('U',mktime($h1,$i1,$s1,$m1,$d1,$y1));
$r2=date('U',mktime($h2,$i2,$s2,$m2,$d2,$y2));
return ($r1-$r2);
}
?>
----
Server IP: 187.16.23.134
Probable Submitter: 200.138.243.82
----
Manual Page -- http://www.php.net/manual/en/function.date-diff.php
Edit -- https://master.php.net/note/edit/98120
Del: integrated -- https://master.php.net/note/delete/98120/integrated
Del: useless -- https://master.php.net/note/delete/98120/useless
Del: bad code -- https://master.php.net/note/delete/98120/bad+code
Del: spam -- https://master.php.net/note/delete/98120/spam
Del: non-english -- https://master.php.net/note/delete/98120/non-english
Del: in docs -- https://master.php.net/note/delete/98120/in+docs
Del: other reasons-- https://master.php.net/note/delete/98120
Reject -- https://master.php.net/note/reject/98120
Search -- https://master.php.net/manage/user-notes.php