note 122627 deleted from function.date by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:20:00 +0000 |
| Subject: | note 122627 deleted from function.date by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210762@lists.php.net to get a copy of this message | ||
Note Submitter: olivertappin at gmail dot com
----
If looking for a simple way to return the week number, using Sunday as the first day of the week,
please bear in mind you will need to cater for the addition when you reach the end of the year.
<?php
function getSundayWeekNumber(\DateTimeInterface $date): int
{
$weekNumber = (int)$date->format('W');
if ($date->format('w') === '0') { // Sunday
$weekNumber += 1;
if (53 === $weekNumber) { // If the week is now 53, subtract 52
$weekNumber -= 52;
}
}
return $weekNumber;
}