Date and Time Functions
933
Mode
First day of week Range
Week 1 is the first week …
2
Sunday
1-53
with a Sunday in this year
3
Monday
1-53
with more than 3 days this year
4
Sunday
0-53
with more than 3 days this year
5
Monday
0-53
with a Monday in this year
6
Sunday
1-53
with more than 3 days this year
7
Monday
1-53
with a Monday in this year
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
0
if you do not use
2
,
3
,
6
, or
7
as the optional
mode
argument:
mysql>
SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
-> 2000, 0
One might argue that MySQL should return
52
for the
WEEK()
[932]
function, because the given
date actually occurs in the 52nd week of 1999. We decided to return
0
instead because we want
the function to return “the week number in the given year.” This makes use of the
WEEK()
[932]
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
7
as the optional
mode
argument.
mysql>
SELECT WEEK('2000-01-01',2);
-> 52
Alternatively, use the
YEARWEEK()
[934]
function:
mysql>
SELECT YEARWEEK('2000-01-01');
-> 199952
mysql>
SELECT MID(YEARWEEK('2000-01-01'),5,2);
-> '52'
•
WEEKDAY(date)
[933]
Returns the weekday index for
date
(
0
= Monday,
1
= Tuesday, …
6
= Sunday).
mysql>
SELECT WEEKDAY('2008-02-03 22:23:00');
-> 6
mysql>
SELECT WEEKDAY('2007-11-06');
-> 1
•
WEEKOFYEAR(date)
[933]
Returns the calendar week of the date as a number in the range from
1
to
53
.
WEEKOFYEAR()
[933]
is a compatibility function that is equivalent to
WEEK(date,3)
[932]
.
mysql>
SELECT WEEKOFYEAR('2008-02-20');
-> 8
•
YEAR(date)
[933]
Returns the year for
date
, in the range
1000
to
9999
, or
0
for the “zero” date.
mysql>
SELECT YEAR('1987-01-01');
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...