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. ??? Quote Link to comment 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'); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
chantown Posted December 16, 2007 Author Share Posted December 16, 2007 great, many thanks! Quote Link to comment 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 } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.