phpbar.de logo

Mailinglisten-Archive

week funktion hat einen Bug ?

week funktion hat einen Bug ?

Andreas Müller mysql at universalware.de
Die Jan 4 08:58:09 CET 2005


Hallo Richard,
nö scheint so zu Funktionieren wie sie soll:

WEEK(date) 
WEEK(date,first) 
With a single argument, returns the week for date, in the range 0 to 53
(yes, there may be the beginnings of a week 53), for locations where Sunday
is the first day of the week. The two-argument form of WEEK() allows you to
specify whether the week starts on Sunday or Monday. The week starts on
Sunday if the second argument is 0, on Monday if the second argument is 1: 
mysql> SELECT WEEK('1998-02-20');
        -> 7
mysql> SELECT WEEK('1998-02-20',0);
        -> 7
mysql> SELECT WEEK('1998-02-20',1);
        -> 8
mysql> SELECT WEEK('1998-12-31',1);
        -> 53

Note: in Version 4.0, WEEK(#,0) was changed to match the calendar in the
USA. Note that if a week is the last week of the previous year, MySQL will
return 0: 
mysql> SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
        -> 2000, 0

One could argue that MySQL should return 52 for the WEEK() function as the
given date is actually the 52 second week of 1999. We decided to return 0
instead as we want the function to return 'the week number in the given
year'. This makes the usage of the WEEK() function reliable when combined
with other functions that extracts a date part from a date. If you would
prefer to know the correct year-week, then you should use the YEARWEEK()
function instead: 
mysql> SELECT YEARWEEK('2000-01-01');
        -> 199952
mysql> SELECT MID(YEARWEEK('2000-01-01'),5,2);
        -> 52

Gruß,
Andreas


-- 
Infos zur Mailingliste, zur Teilnahme und zum An- und Abmelden unter
-->>  http://www.4t2.com/mysql 


php::bar PHP Wiki   -   Listenarchive