Fenhopi Posted November 14, 2010 Share Posted November 14, 2010 Hi, I have a database where I store times with the Now(); function. What I want is: When the viewer looks at the post, instead of it saying: Posted: 2010-11-14 19:08:14, I want it to say posted: x hours ago, Posted: x days ago, etc. Any help with this would be appreciated! Link to comment https://forums.phpfreaks.com/topic/218671-getting-amount-of-hours-since-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2010 Share Posted November 14, 2010 You can simply calculate the differences in your query and then use the information any way you want when you display it (i.e. if days are zero, display the hours...) - SELECT TIMESTAMPDIFF(HOUR,now(),your_datetime_column) as hours, TIMESTAMPDIFF(DAY,now(),your_datetime_column) as days Link to comment https://forums.phpfreaks.com/topic/218671-getting-amount-of-hours-since-date/#findComment-1134180 Share on other sites More sharing options...
Fenhopi Posted November 15, 2010 Author Share Posted November 15, 2010 Thank you, man! How would I remove the - in front of number though? if($Time contains("-"){ Don't know how to post number without - symbol } Link to comment https://forums.phpfreaks.com/topic/218671-getting-amount-of-hours-since-date/#findComment-1134212 Share on other sites More sharing options...
PFMaBiSmAd Posted November 15, 2010 Share Posted November 15, 2010 I would reverse the order of the two arguments (it calculates datetime_expr2 – datetime_expr1.) TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) Link to comment https://forums.phpfreaks.com/topic/218671-getting-amount-of-hours-since-date/#findComment-1134217 Share on other sites More sharing options...
Fenhopi Posted November 15, 2010 Author Share Posted November 15, 2010 Thank you! Highly appreciate it! Link to comment https://forums.phpfreaks.com/topic/218671-getting-amount-of-hours-since-date/#findComment-1134219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.