Jump to content

Use mysql datetime to show difference between 2 times


monkeytooth

Recommended Posts

I have a timestamp in DATETIME format (Y-m-d H:i:s), this time stamp when generated generates for a time in the future. Say a day or 2 from now for example. What I am trying to figure out is How do i compare the diffrence of the current time and the future time thats stored.

 

im not sure if I should use strtotime() or something else with the mysql time stamp to make it something I can work with in PHP. Or maybe Im thinking wrong and theres an easier way.

That is good i didnt know I could do that within sql itself and will be handy for something else im intent on doing later, but Im trying to do currently is create a timestamp client side one thats not stored in the database and then compare to the one stored in the database. Im just confused a bit as how to do that, I recently made the jump to using sql timestamps so they are still a little grey to me as how to work with them within php do I convert them to a unix timestamp format someway or is there a way to check the one generated client side vs the one I am pulling out of the DB through the script.

Hi,

 

To make it on an illustrative note, you have to convert into timestamp to calculate the difference.

 

time() function is a php function which gives the current timestamp

 

unix_timestamp(date) gives you the timestamp of your stored date.

 

You can use these two timestamp variables in php to calculate the difference which will be in seconds

Archived

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

×
×
  • 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.