monkeytooth Posted April 19, 2010 Share Posted April 19, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198983-use-mysql-datetime-to-show-difference-between-2-times/ Share on other sites More sharing options...
themistral Posted April 19, 2010 Share Posted April 19, 2010 Have a look at the DATEDIFF function - this seems like what you might need. http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff Link to comment https://forums.phpfreaks.com/topic/198983-use-mysql-datetime-to-show-difference-between-2-times/#findComment-1044543 Share on other sites More sharing options...
monkeytooth Posted April 19, 2010 Author Share Posted April 19, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198983-use-mysql-datetime-to-show-difference-between-2-times/#findComment-1044743 Share on other sites More sharing options...
jagdish kothapalle Posted April 20, 2010 Share Posted April 20, 2010 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 Link to comment https://forums.phpfreaks.com/topic/198983-use-mysql-datetime-to-show-difference-between-2-times/#findComment-1045039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.