How to Get Start & End dates of a Week by given Date

The following function gets start and end date of a week for a given date supplied in valid date string format. In the following function $week is the number of week in the year. For example the current week is week number 43. In the following function $year is year in YYYY format. For example, current year which is 2016. Here is the function to get start date and end date by a given date. For example
_getWeekStartEndDatesByDate(‘2016-10-26’)

function _getWeekStartEndDatesByDate($current_date) {
$week = date('W', strtotime($current_date));
$year = date('Y', strtotime($current_date));
return _getWeekStartEndDatesByWeekAndYear($week, $year);
}

function _getWeekStartEndDatesByWeekAndYear($week, $year) {
$dto = new DateTime();
$result['start'] = $dto->setISODate($year, $week, 0)->format('Y-m-d');
$result['end'] = $dto->setISODate($year, $week, 6)->format('Y-m-d');
return $result;
}

I hope someone finds it helpful.

2 thoughts on “How to Get Start & End dates of a Week by given Date

Leave a Reply