Oracle 5.0 Reference Manual page 953

Table of Contents

Advertisement

Mode
First day of week Range
2
Sunday
3
Monday
4
Sunday
5
Monday
6
Sunday
7
Monday
mysql>
SELECT WEEK('2008-02-20');
-> 7
mysql>
SELECT WEEK('2008-02-20',0);
-> 7
mysql>
SELECT WEEK('2008-02-20',1);
-> 8
mysql>
SELECT WEEK('2008-12-31',1);
-> 53
Note that if a date falls in the last week of the previous year, MySQL returns
6, or
as the optional
7
mysql>
SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
-> 2000, 0
One might argue that MySQL should return
date actually occurs in the 52nd week of 1999. We decided to return
the function to return "the week number in the given year." This makes use of the
function reliable when combined with other functions that extract a date part from a date.
If you would prefer the result to be evaluated with respect to the year that contains the first day of the
week for the given date, use 0, 2, 5, or
mysql>
SELECT WEEK('2000-01-01',2);
-> 52
Alternatively, use the
mysql>
SELECT YEARWEEK('2000-01-01');
-> 199952
mysql>
SELECT MID(YEARWEEK('2000-01-01'),5,2);
-> '52'
[933]
WEEKDAY(date)
Returns the weekday index for
mysql>
SELECT WEEKDAY('2008-02-03 22:23:00');
-> 6
mysql>
SELECT WEEKDAY('2007-11-06');
-> 1
WEEKOFYEAR(date)
Returns the calendar week of the date as a number in the range from
[933]
WEEKOFYEAR()
mysql>
SELECT WEEKOFYEAR('2008-02-20');
-> 8
[933]
YEAR(date)
Returns the year for date, in the range
mysql>
SELECT YEAR('1987-01-01');
Date and Time Functions
1-53
1-53
0-53
0-53
1-53
1-53
argument:
mode
52
as the optional
7
[934]
function:
YEARWEEK()
date (0
= Monday,
[933]
is a compatibility function that is equivalent to
1000
933
Week 1 is the first week ...
with a Sunday in this year
with more than 3 days this year
with more than 3 days this year
with a Monday in this year
with more than 3 days this year
with a Monday in this year
for the
[932]
function, because the given
WEEK()
0
argument.
mode
= Tuesday, ...
1
6
WEEK(date,3)
to 9999, or
for the "zero" date.
0
if you do not use 2, 3,
0
instead because we want
[932]
WEEK()
= Sunday).
to 53.
1
[932].

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents