Jump to content

Getting amount of hours since date?


Fenhopi

Recommended Posts

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

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

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.