cmcdonld Posted November 12, 2009 Share Posted November 12, 2009 This is a simple function to check a date between two dates. It works for anything in the current year, but I want it to roll through 2010 and it fails with the end_date. I would typically write this function in a simpler way, but this was how I tested where it was failing, any suggestions on why it won't check into 2010? <?php function opendates(){ $start_date = date("m/d/Y", mktime(0,0,0,11,01,2009)); $end_date = date("m/d/Y", mktime(0,0,0,01,20,2010)); $today_date = date("m/d/Y", mktime(0,0,0,date(m),date(d),date(Y))); if($today_date >= $start_date) { if($today_date <= $end_date) { echo "Success"; } else { echo "Failed on 2nd if"; } } else { echo "Failed on first if"; } } ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/181262-solved-simple-date-function-not-responding/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 12, 2009 Share Posted November 12, 2009 You cannot do greater-than/less-than comparisons on dates unless the format can be compared by magnitude. This either requires using a Unix timestamp or the fields making up the date must be ordered left-right Year - month - day and the length of the corresponding field in each value is the same (you need leading zeros.) Link to comment https://forums.phpfreaks.com/topic/181262-solved-simple-date-function-not-responding/#findComment-956253 Share on other sites More sharing options...
cmcdonld Posted November 12, 2009 Author Share Posted November 12, 2009 That worked. Thanks for the info! Have a good day. Link to comment https://forums.phpfreaks.com/topic/181262-solved-simple-date-function-not-responding/#findComment-956263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.