Jump to content

Working with time


GingerRobot

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:
[code]
<?php
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;
}
?>
[/code]

Any help would be much appreciated.
Link to comment
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.

Doh!

Thanks anyway :D
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.