Date and Time Functions
923
•
DAYNAME(date)
[923]
Returns the name of the weekday for
date
. As of MySQL 5.0.25, the language used for the name is
controlled by the value of the
lc_time_names
[462]
system variable (
Section 10.7, “MySQL Server
Locale Support”
).
mysql>
SELECT DAYNAME('2007-02-03');
-> 'Saturday'
•
DAYOFMONTH(date)
[923]
Returns the day of the month for
date
, in the range
1
to
31
, or
0
for dates such as
'0000-00-00'
or
'2008-00-00'
that have a zero day part.
mysql>
SELECT DAYOFMONTH('2007-02-03');
-> 3
•
DAYOFWEEK(date)
[923]
Returns the weekday index for
date
(
1
= Sunday,
2
= Monday, …,
7
= Saturday). These index
values correspond to the ODBC standard.
mysql>
SELECT DAYOFWEEK('2007-02-03');
-> 7
•
DAYOFYEAR(date)
[923]
Returns the day of the year for
date
, in the range
1
to
366
.
mysql>
SELECT DAYOFYEAR('2007-02-03');
-> 34
•
EXTRACT(unit FROM date)
[923]
The
EXTRACT()
[923]
function uses the same kinds of unit specifiers as
DATE_ADD()
[919]
or
DATE_SUB()
[922]
, but extracts parts from the date rather than performing date arithmetic.
mysql>
SELECT EXTRACT(YEAR FROM '2009-07-02');
-> 2009
mysql>
SELECT EXTRACT(YEAR_MONTH FROM '2009-07-02 01:02:03');
-> 200907
mysql>
SELECT EXTRACT(DAY_MINUTE FROM '2009-07-02 01:02:03');
-> 20102
mysql>
SELECT EXTRACT(MICROSECOND
->
FROM '2003-01-02 10:30:00.000123');
-> 123
•
FROM_DAYS(N)
[923]
Given a day number
N
, returns a
DATE
value.
mysql>
SELECT FROM_DAYS(730669);
-> '2007-07-03'
Use
FROM_DAYS()
[923]
with caution on old dates. It is not intended for use with values that
precede the advent of the Gregorian calendar (1582). See
Section 12.8, “What Calendar Is Used By
MySQL?”
.
•
FROM_UNIXTIME(unix_timestamp)
[923]
,
FROM_UNIXTIME(unix_timestamp,format)
[923]
Returns a representation of the
unix_timestamp
argument as a value in
'YYYY-MM-DD
HH:MM:SS'
or
YYYYMMDDHHMMSS.uuuuuu
format, depending on whether the function is used in a
string or numeric context. The value is expressed in the current time zone.
unix_timestamp
is an
internal timestamp value such as is produced by the
UNIX_TIMESTAMP()
[931]
function.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...