ballhogjoni Posted December 4, 2010 Share Posted December 4, 2010 I have this code that compares date times but im not sure if its correct. if("2008-08-10 00:00:00.0" > strtotime("now")) { echo "here"; } The code echo's here, but it shouldn't because the time is less than the current time. Any ideas? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 4, 2010 Share Posted December 4, 2010 1. Read the manual. 2. Your comparison is backwards. Assuming that 2008 date is just an example, if ("2008-08-10 00:00:00" Note that it takes the current time into account too. If today was 2008-08-10 and it was one second past midnight, the condition would pass. Quote Link to comment Share on other sites More sharing options...
chronister Posted December 5, 2010 Share Posted December 5, 2010 Learn to love the date function and strtotime()... Any time string like you have 2008-08-10 00:00:00, or 10/08/2010 or 02-12-10 5:00:00 pm.... will have to be ran through strtotime before making any comparison operations. I could be wrong, but I don't think requinix's example will work. I am not sure that you can compare a date in that format. I could be wrong, so try it and see.. if it does not work, then try this one... if (strtotime("2008-08-10 00:00:00") < strtotime("now") ) {...... Quote Link to comment Share on other sites More sharing options...
chronister Posted December 5, 2010 Share Posted December 5, 2010 huh... had to reply and say that I was wrong... requinix was right... you can compare the 2 strings like that. Cool... learn something new all the time. 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.