News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Leonid Mamchenkov' Blog:
PHP date() and 53 weeks
February 11, 2010 @ 12:12:09

In doing some work with data and date ranges, Leonid Mamchenkov came across something strange about the "weeks" that the date and time functions in PHP work on. Sometimes, there's not always 52 weeks in a year.

With code as simple and straight-forward as [our example], you'd probably look for the problem elsewhere. Maybe it's your statistical data which is wrong, or the graph is not generated properly. But the problem is here.

How many weeks do you think there are in a year? A common knowledge says 52. However, if you think for a moment about how the weeks are related to the year, you'll realize that the first and last weeks don't necessary start and end at the edge of the year.

So, when using the date function, you might not get quite what you were expecting. It works more correctly and can include the extra "week" if there's enough of an overlap. The "W" parameter (for "week") works off of the ISO-8601 week number for the year, not the general calendar weeks.

1 comment voice your opinion now!
week datetime iso8601 date


blog comments powered by Disqus

Similar Posts

Derick Rethans: ISO 8601 week dates

PHPFreaks.com: Working with dates in PHP

Derick Rethans's Blog: Obtaining the next month in PHP

PHPClasses.org: Lately in PHP podcast episode 17 - PHP 5.4 & PHP-GTK in the Browser

Joshua Eichorn\'s Blog: HTML_AJAX Feature of the Week - Javascript Behaviors


Community Events





Don't see your event here?
Let us know!


bugfix library podcast conference community deployment zendserver tips introduction api interview series laravel language developer list release voicesoftheelephpant symfony framework

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework