Jaynesh Posted July 11, 2011 Share Posted July 11, 2011 hello I'm working on a basic script where users can post things. On each post how do a display the time and how many hours ago it was posted? For e.g Jacob - this is my post Posted 6 hours ago Link to comment https://forums.phpfreaks.com/topic/241735-adding-time-to-post/ Share on other sites More sharing options...
freelance84 Posted July 11, 2011 Share Posted July 11, 2011 You need to store somewhere the time this was created: Make a new field in your table eg: postTime and input into it either a unix timestamp or a mysql date/time when creating the post entry. Then when pulling the post from the table, get the time with it and process accordingly Link to comment https://forums.phpfreaks.com/topic/241735-adding-time-to-post/#findComment-1241540 Share on other sites More sharing options...
gizmola Posted July 11, 2011 Share Posted July 11, 2011 You need to store somewhere the time this was created: Make a new field in your table eg: postTime and input into it either a unix timestamp or a mysql date/time when creating the post entry. Then when pulling the post from the table, get the time with it and process accordingly With mysql the easiest way is to use a timestamp column. It has the advantage of space savings as well (4 bytes vs. 8 bytes for a date/time) as well as automation functionality. http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html Link to comment https://forums.phpfreaks.com/topic/241735-adding-time-to-post/#findComment-1241541 Share on other sites More sharing options...
freelance84 Posted July 11, 2011 Share Posted July 11, 2011 Ah cool. Cheers. I'll have a read through your site Link to comment https://forums.phpfreaks.com/topic/241735-adding-time-to-post/#findComment-1241550 Share on other sites More sharing options...
$php_mysql$ Posted July 11, 2011 Share Posted July 11, 2011 `postTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, Link to comment https://forums.phpfreaks.com/topic/241735-adding-time-to-post/#findComment-1241565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.