note 60751 added to function.mktime
| From: | McDonk2kathotmaildotcom at osu1 dot php dot net | Date: | Sun, 15 Jan 2006 22:19:44 +0000 |
| Subject: | note 60751 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101874@lists.php.net to get a copy of this message | ||
I found this the other night and found it needed a couple tweeks to work. I few values were switched
but now it works. This function finds the amount of days, hours, and minutes between two different
dates/times. Thanks Tone.
<?php
function unix_diff($first_date,$first_time,$second_date,$second_time)
{
// Author: Tone.
// Date : 15-12-2003.
// Ref: Dates go in "2003-12-31".
// Ref: Times go in "12:59:13".
// Ref: mktime(HOUR,MIN,SEC,MONTH,DAY,YEAR).
// Splits the dates into parts, to be reformatted for mktime.
$first_date_ex = explode("-",$first_date);
$first_time_ex = explode(":",$first_time);
$second_date_ex = explode("-",$second_date);
$second_time_ex = explode(":",$second_time);
// makes the dates and times into unix timestamps.
$first_unix = mktime($first_time_ex[0], $first_time_ex[1], $first_time_ex[2],
$first_date_ex[1], $first_date_ex[2], $first_date_ex[0]);
$second_unix = mktime($second_time_ex[0], $second_time_ex[1], $second_time_ex[2],
$second_date_ex[1], $second_date_ex[2], $second_date_ex[0]);
// Gets the difference between the two unix timestamps.
$timediff = $first_unix-$second_unix;
// Works out the days, hours, mins and secs.
$days=intval($timediff/86400);
$remain=$timediff%86400;
$hours=intval($remain/3600);
$remain=$remain%3600;
$mins=intval($remain/60);
$secs=$remain%60;
// Returns a pre-formatted string. Can be chagned to an array.
return $days . " days " . $hours . " hours<br> " . $mins . "
mins";
} ?>
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60751
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60751&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60751&report=yes
Search -- http://master.php.net/manage/user-notes.php