note 80148 modified in function.date by derick

From: Date: Wed, 07 May 2008 18:18:32 +0000
Subject: note 80148 modified in function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139148@lists.php.net to get a copy of this message
date("W") returns the iso8601 week number, while date("Y") returns the _current_ year. This can lead to odd results. For example today (dec 31, 2007) it returns 1 for the week and of course 2007 for the year. This is not wrong in a strict sense because iso defines this week as the first of 2008 while we still have 2007. So, if you don't have another way to safely retrieve the year according to the iso8061 week-date - strftime("%G") doesn't work on some systems -, you should be careful when working with date("W"). For most cases strftime("%W") should be a safe replacement. [edit: Much easier is to use "o" (lower case O) instead of "Y"] --was-- date("W") returns the iso8601 week number, while date("Y") returns the _current_ year. This can lead to odd results. For example today (dec 31, 2007) it returns 1 for the week and of course 2007 for the year. This is not wrong in a strict sense because iso defines this week as the first of 2008 while we still have 2007. So, if you don't have another way to safely retrieve the year according to the iso8061 week-date - strftime("%G") doesn't work on some systems -, you should be careful when working with date("W"). For most cases strftime("%W") should be a safe replacement. http://php.net/manual/en/function.date.php

« previous php.notes (#139148) next »