Saturday 30 May 2015

How to get week starting date of a date in PHP?

$W = date('W',strtotime(date('Y-m-d'))); // Get the week number
$sunday = date(datetime::ISO8601, strtotime(date('Y') . "W" . $W . "0")); // "0" means Sunday, "1" means Monday, ... , "7" means next Sunday
echo date('Y-m-d',strtotime($sunday));
$nextSunday = date(datetime::ISO8601, strtotime(date('Y') . "W" . $W . "7"));
echo date('Y-m-d',strtotime($nextSunday));

No comments:

Post a Comment

Your comment is so valuable as it would help me in my growth of knowledge.