I have 2 date range:
2014/01/28 - 2015/10/10 //first
2015/10/11 - 2014/01/27 //second
How to check using DateTime object in PHP only the month, day and ignoring the year if 2015/06/24
is between first or second date range. The expected answer that 2015/06/24
is between first date range, because 06/24 is between 01/28 - 10/10
Thank you.
$date1 = new DateTime("2014/01/28");
$date2 = new DateTime("2015/10/10");
$date_compare = new DateTime("2015/06/24");
if ($date_compare->format('m/d') > $date1->format('m/d') &&
$date_compare->format('m/d') <= $date2->format('m/d')) {
echo $date_compare->format('m/d') . "fits";
}
http://php.net/manual/en/datetime.diff.php < this will help you out with this
If I'm understanding correctly, I think this method should take care of you.
function isWithinDayOfYearRange($rangeBegin, $rangeEnd, $dateToCheck)
{
return $dateToCheck->format('md') > $rangeBegin->format('md') &&
$dateToCheck->format('md') < $rangeEnd->format('md');
}