I have two dates
$start_date = '2015-09-21';
$end_Date = '2016-09-21';
What I want to get, like this
Week = Monday Friday
36 = 2015-09-21 2015-09-25
37 = 2015-09-28 2015-10-02
38 = 2015-10-05 2015-10-09
.
.
38 = 2016-09-19 2016-09-24
The difference in date may be one year or more. What I need to get is accurate every week from Monday and Friday between this time interval.
I used this method
$weeks = array();
while ($start_date < $end_Date )
{
$weeks[] = date('W', $start_date );
$start_date += strtotime('+1 week', 0);
}
function getStartAndEndDate($week, $year)
{
$time = strtotime("1 January $year", time());
$day = date('w', $time);
$time += ((7*$week)+1-$day)*24*3600;
$return[0] = date('Y-m-d', $time);
$time += 6*24*3600;
$return[1] = date('Y-m-d', $time);
return $return;
}
When I call this function, I need to specify the week number and year to get the exact dates. But I can’t get a year from a particular week. I managed to get a week from the start or end date.
$current_year = date("Y", strtotime($fromdate));
Anyone suggested I get the exact year with the week number
source
share