chantown Posted December 16, 2007 Share Posted December 16, 2007 Hi, I have a very simple question I know that if you do time(), it will give u the timestamp right now. Let's say people on my website makes a post, and i record that timestamp. How do I determine if that timestamp is on today? For example, i want it to show Posted TODAY if it was really posted today, but say Posted DEC 5th, if it was not posted today. ??? Link to comment https://forums.phpfreaks.com/topic/81875-solved-time-how-do-i-know-if-it-is-today/ Share on other sites More sharing options...
axiom82 Posted December 16, 2007 Share Posted December 16, 2007 Your question was hard to interpret. Maybe you are looking for strtotime('today'); Link to comment https://forums.phpfreaks.com/topic/81875-solved-time-how-do-i-know-if-it-is-today/#findComment-415999 Share on other sites More sharing options...
AntiScourge Posted December 16, 2007 Share Posted December 16, 2007 Not sure if this is the simplest way... $currentDate = date("F d y",time()); if ($currentDate == date("F d y", $userSubmittedTime)) { echo "Posted Today" } It formats the two dates into strings that show Month Day Year and compares them. ex December 15 2007 Link to comment https://forums.phpfreaks.com/topic/81875-solved-time-how-do-i-know-if-it-is-today/#findComment-416002 Share on other sites More sharing options...
chantown Posted December 16, 2007 Author Share Posted December 16, 2007 great, many thanks! Link to comment https://forums.phpfreaks.com/topic/81875-solved-time-how-do-i-know-if-it-is-today/#findComment-416004 Share on other sites More sharing options...
corbin Posted December 16, 2007 Share Posted December 16, 2007 A mathematical way to do it, which I believe would be faster, although I'm not sure, would be: $now = time(); $then = <posted time>; if($now - $then <= 86400) { //less than or exactly 1 day ago } Link to comment https://forums.phpfreaks.com/topic/81875-solved-time-how-do-i-know-if-it-is-today/#findComment-416128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.