News Feed
Sections




News Archive
feed this:

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

Derick Rethans:
ISO 8601 week dates
September 24, 2013 @ 09:54:31

Derick Rethans has a new post with details about handling ISO 8601 dates in PHP via the DateTime functionality. It's a response to some bugs filed having to do with week numbering.

Week numbers are defined in this same ISO 8601 standard. Each year has 52 or 53 weeks and weeks always start on a Monday. Week number 1 of each year is the first week in a year that has the first Thursday of the year, or in other words, the week containing January 4th.

He talks about some of the date format arguments that use would use when working with the ISO 8601 formatting and how it relates to the calendar year. He points out that the "Y" format specifier is not the same as the "o" - the first being the calendar year while the second relates to the ISO 8601 year.

As conclusion, this article shows that there are two ways representing dates in PHP. In the Gregorian1 calendar with year, month and day (of month), and in the ISO 8601 calendar with year, week and day (of week). The format characters for the two different years are either Y or o and they should not be confused.
0 comments voice your opinion now!
iso8601 date datetime format specifier gregorian calendar difference

Link: http://derickrethans.nl/iso-8601-weeks.html

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


Derick Rethans' Blog:
Calculating start and end dates of a week
September 06, 2006 @ 07:03:24

With just a quick handy code snippet posted on his blog today, Derick Rethans shares these two lines to help grab the start and end dates of a week in question.

A friend asked "How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher.

The code makes use of the ISO8601 datetime functionality to grab the correct value from a strtotime command. Derick also briefly explains how it all works.

0 comments voice your opinion now!
start date end week strtotime iso8601 datetime format start date end week strtotime iso8601 datetime format



Community Events





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


list introduction framework release podcast interview security voicesoftheelephpant laravel conference version library language community composer series artisanfiles symfony opinion tool

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