Jump to content


This topic is now archived and is closed to further replies.


Working with time

Recommended Posts

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:37

I 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:
function 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;

Any help would be much appreciated.

Share this post

Link to post
Share on other sites
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.


Thanks anyway :D

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.