hassank1 Posted July 20, 2008 Share Posted July 20, 2008 I've a variable $PostDate .. which I get from a datetime mysql field I want to check if this date is today so I echo "today" or if it's yesterday I echo "yesterday" Quote Link to comment Share on other sites More sharing options...
Guest Xanza Posted July 20, 2008 Share Posted July 20, 2008 It would depend on the format of $PostDate... For example, if $PostDate shows the date as: "Weekday, Month date" (Example: Monday, April 25) then this would work: <?php if($PostDate == date("l, F d")){ echo "Today"; } if($PostDate == date("l, F d")-1){ echo "Yesterday"; } ?> This should work, depending how your initial SQL variable is output, just change date() to suit your needs. Hope this helped! Quote Link to comment Share on other sites More sharing options...
hassank1 Posted July 20, 2008 Author Share Posted July 20, 2008 Thx , I'll check it .. btw this is an example of a $postdate output : 2008-04-18 04:38:08 Quote Link to comment Share on other sites More sharing options...
Guest Xanza Posted July 20, 2008 Share Posted July 20, 2008 Then make the date() function match your SQL output, use php.net to help you: http://us2.php.net/manual/en/function.date.php Quote Link to comment Share on other sites More sharing options...
hassank1 Posted July 20, 2008 Author Share Posted July 20, 2008 I've used your code to implement these functions .. and everything worked just fine function isToday($date) //check if it's today { $date = date("l, F d",strtotime($date)); if($date == date("l, F d")) return true; else return false; } function isYesterday($date) //check if it's yesterday { $date = date("l, F d",strtotime($date)); if($date == date("l, F d")-1) return true; else return false; } Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 20, 2008 Share Posted July 20, 2008 Instead of using DateTime in my sql use timestamp i believe it is twice as fast...and your code will still work as it returns in the same format Quote Link to comment Share on other sites More sharing options...
hassank1 Posted July 20, 2008 Author Share Posted July 20, 2008 OK .. thx for the advice . 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.