How to get all week start date and end date within a date range in PHP?
Week start = Sunday and week end = Saturday
Input
$start_date=’2013-02-01′
$end_date = ‘2013-02-28’
Output
start date=’2013-02-01′ End date =’2013-02-02′
start date=’2013-02-03′ End date =’2013-02-09′
start date=’2013-02-10′ End date =’2013-02-16′
start date=’2013-02-17′ End date =’2013-02-23′
start date=’2013-02-24′ End date =’2013-02-28′
Below code return the week start and end of the date given
function getWeekDates($date)
{
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); //Returns the date of monday in week
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7")); //Returns the date of sunday in week
echo "Start Date-->".$from."End Date -->".$to;//Output : Start Date-->2012-09-03 End Date-->2012-09-09
}
How can I get the result above?
Try this one…
See Codepad.