JustinK101 Posted August 4, 2008 Share Posted August 4, 2008 I have a `datetime` column `date_updated` that comes from mysql. I would like to format the datetime to subtract from now() to do the following logic: You updated your profile X seconds ago. (if difference 0 - 59 seconds) You updated your profile X minutes ago. (if difference 60 - 3599 seconds) You updated your profile X hours ago. (if difference 3600 - 86399 seconds) You updated your profile X days ago. (if difference >= 86400) Thanks for the help guys. Link to comment https://forums.phpfreaks.com/topic/118162-datetime-to-seconds-minutes-hours-days-differences/ Share on other sites More sharing options...
MatthewJ Posted August 4, 2008 Share Posted August 4, 2008 Just use strtotime() on the field in question, subtract your result from the current time, then run it through a switch or some ifs to find what to print. <?php $temp = strtotime($row['date']); $temp_diff = time() - $temp; if($temp_diff <= 59) { echo "You updated your profile $temp_diff seconds ago"; } // And so on ?> Link to comment https://forums.phpfreaks.com/topic/118162-datetime-to-seconds-minutes-hours-days-differences/#findComment-607965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.