The date function between two time periods
When I code my website or problem of time in the conditional.
Eg: I want to display a sentence introduced for certain events in a certain period of time, if time is automatic event notifications will disappear and appear normal information that is not information about that event.
For this I use a function to calculate the amount of time and then compare the current date and the day of that period, if it’s around that time it would appear that message.
This is the code that around the time that I used to use
function dates_inbetween($date1, $date2)
{
$day = 60*60*24;
$date1 = strtotime($date1);
$date2 = strtotime($date2);
$days_diff = round(($date2 - $date1)/$day); // Unix time difference devided by 1 day to get total days in between
$dates_array = array();
$dates_array[] = date('Y-m-d',$date1);
for($x = 1; $x < $days_diff; $x++)
{
$dates_array[] = date('Y-m-d',($date1+($day*$x)));
}
$dates_array[] = date('Y-m-d',$date2);
return $dates_array;
}
// Usage
$dates_array = dates_inbetween('2001-12-28', '2002-01-01');
You can use the above code and develop it according to your requirements.