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? Link to comment https://forums.phpfreaks.com/topic/220682-how-to-compare-dates/ 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. Link to comment https://forums.phpfreaks.com/topic/220682-how-to-compare-dates/#findComment-1143032 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") ) {...... Link to comment https://forums.phpfreaks.com/topic/220682-how-to-compare-dates/#findComment-1143048 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. Link to comment https://forums.phpfreaks.com/topic/220682-how-to-compare-dates/#findComment-1143049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.