GingerRobot Posted August 2, 2006 Share Posted August 2, 2006 Im looking for an easy way to find out how long has passed betweed two times that are in the mysql datetime format, for instance:2006-08-02 01:01:37I have made a function that explodes the string into its components and then uses mktime() to get a unix timestamp and then compare the 2 unix timestamps, but this seems long winded way of going about. Is there something more simple?Here is the function i was using:[code]<?phpfunction to_time($datetime){ $seperate = explode(" ",$datetime); $date = explode("-",$seperate[0]); $years = $date[0]; $months = $date[1]; $days = $date[2]; $time = explode(":",$seperate[1]); $hours = $time[0]; $minutes = $time[1]; $seconds = $time[2]; $timestamp = mktime($hours,$minutes,$seconds,$months,$days,$years); return $timestamp; }?>[/code]Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 Ever used MySql functions DATEDIFF() and TIMEDIFF()?Ronald ;D Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 2, 2006 Author Share Posted August 2, 2006 No, and i dont think those would quite do as i want because one of times in question is generated by the php script. But ive just realised i dont need to use the function i made because i can use another mysql function, UNIX_TIMESTAMP, to convert the one from the database and just generate a unix timestamp in php.Doh!Thanks anyway :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.