mrjonnytou Posted July 8, 2008 Share Posted July 8, 2008 Hi, I'm struggling with the syntax when it comes to checking if a given date lies between two dates. my code so far $deadline = strtotime($date); $now = time(); $six_months = $now + 60*60*24*180; $one_year = $now + 60*60*24*360; $three_years = $now + 60*60*24*1080; if ($deadline => $now && =< $six_months){ //do something } elseif ($deadline >= $six_months && <= $one_year){ //do something } elseif ($deadline >= $six_months && <= $three_years){ //do something else } Any suggestions? Link to comment https://forums.phpfreaks.com/topic/113738-solved-if-between-two-dates-do-this/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 8, 2008 Share Posted July 8, 2008 The distributive property does not work in programming. You must explicitly list what comparisons you want (also, the => must be >= and =< must be <=) - if ($deadline >= $now && $deadline <= $six_months){ Link to comment https://forums.phpfreaks.com/topic/113738-solved-if-between-two-dates-do-this/#findComment-584490 Share on other sites More sharing options...
mrjonnytou Posted July 8, 2008 Author Share Posted July 8, 2008 Thanks, it now works! Link to comment https://forums.phpfreaks.com/topic/113738-solved-if-between-two-dates-do-this/#findComment-584498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.