01-16-2004, 03:56 PM
What would be the best way to calculate the difference between a start date and time and an ending date and time. Would like to display the number of days, hour, minutes and seconds. Any code examples or links to articles and tutorials would be appreciated. Thank you.
01-16-2004, 04:20 PM
would these times be a constant or virtual time
01-16-2004, 04:26 PM
They come from a MySql database file that is updated by a Help Desk application. Among other things it stores date and time a support request was created and date and time it was completed. The format for the date is YYYYMMDD and time is HHMMSS. The "created" date is separate from the "created" time and the same for completed. Hope this gives a better explanation. If you could point me to some examples or tutorials that would be great. Thank you.
01-16-2004, 04:51 PM
I did find this one over at the fourms at PHP Builder. I should be able to incorporate it into my existing code to do what I want. Thank you for your help.
// Author: Tone.
// Date : 15-12-2003.
// Ref: Dates go in "12 31 2003".
// 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,$first_time_ex,$first_time_ex,$first_date_ex,$first_date_ex,$first_date_ex);
$second_unix = mktime($second_time_ex,$second_time_ex,$second_time_ex,$second_date_ex,$second_date_ex,$second_date_ex);
// Gets the difference between the two unix timestamps.
$timediff = $first_unix-$second_unix;
// Works out the days, hours, mins and secs.
// Returns a pre-formatted string. Can be chagned to an array.
return $days." days, ".$hours." hours, ".$mins." mins, ".$secs." secs.";
echo date_diff( '01 16 2004','09 10 00','01 16 2004','09 11 00' ) ;
01-16-2004, 06:59 PM
looks good to me, good luck :thumbsup:
01-16-2004, 11:00 PM
if both dates come from the MySQL database then you should be able to use MySQL's built in functions for dat and time processing:
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.