Skip to content

Instantly share code, notes, and snippets.

@borazslo
Created September 13, 2014 17:24
Show Gist options
  • Save borazslo/84819edbf4dea7a67e2e to your computer and use it in GitHub Desktop.
Save borazslo/84819edbf4dea7a67e2e to your computer and use it in GitHub Desktop.
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