Created
September 13, 2014 17:24
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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