Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to check if a date is in a given range of day+month?
$date = "20".sprintf('%02d',rand(0,22))."-".sprintf('%02d',rand(1,12))."-".sprintf('%02d',rand(1,29));
$start = sprintf('%02d',rand(1,12))."-".sprintf('%02d',rand(1,29));
$end = sprintf('%02d',rand(1,12))."-".sprintf('%02d',rand(1,29));
echo "Is ".$date." between ".$start." and ".$end."? ";
if("2000".$start < "2000".$end) {
$year = date('Y',strtotime($date));
if(strtotime($year."-".$start) <= strtotime($date) AND strtotime($date) <= strtotime($year."-".$end)) echo "yes";
else echo "no";
} else {
$year = date('Y',strtotime($date));
if(strtotime($year."-".$start) > strtotime($date) AND strtotime($date) > strtotime($year."-".$end)) echo "no";
else echo "yes";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.