MySQL recognizes
DATETIME
• As a string in either
'YYYY-MM-DD HH:MM:SS'
syntax is permitted here, too: Any punctuation character may be used as the delimiter between
date parts or time parts. For example,
11*30*45', and
'2012/12/31
• As a string with no delimiters in either
that the string makes sense as a date. For example,
are interpreted as
'2007-05-23
minute part) and becomes
• As a number in either
makes sense as a date. For example,
'1983-09-05
13:28:00'.
A
or
DATETIME
TIMESTAMP
(6 digits) precision. Although this fractional part is recognized, it is discarded from values stored into
or
DATETIME
TIMESTAMP
Section 11.1.5.6, "Fractional Seconds in Time
Dates containing two-digit year values are ambiguous because the century is unknown. MySQL
interprets two-digit year values using these rules:
• Year values in the range
• Year values in the range
See also
Section 11.1.5.8, "Two-Digit Years in
For values specified as strings that include date part delimiters, it is unnecessary to specify two digits
for month or day values that are less than 10.
for values specified as strings that include time part delimiters, it is unnecessary to specify two digits
for hour, minute, or second values that are less than 10.
'2015-10-30
01:02:03'.
Values specified as numbers should be 6, 8, 12, or 14 digits long. If a number is 8 or 14 digits long, it
is assumed to be in
YYYYMMDD
digits. If the number is 6 or 12 digits long, it is assumed to be in
that the year is given by the first 2 digits. Numbers that are not one of these lengths are interpreted as
though padded with leading zeros to the closest length.
Values specified as nondelimited strings are interpreted according their length. For a string 8 or 14
characters long, the year is assumed to be given by the first 4 characters. Otherwise, the year is
assumed to be given by the first 2 characters. The string is interpreted from left to right to find year,
month, day, hour, minute, and second values, for as many parts as are present in the string. This
means you should not use strings that have fewer than 6 characters. For example, if you specify
'9903', thinking that represents March, 1999, MySQL converts it to the "zero" date value. This occurs
because the year and month values are
you can explicitly specify a value of zero to represent missing month or day parts. For example, to
insert the value '1999-03-00', use '990300'.
MySQL recognizes
TIME
• As a string in
'D HH:MM:SS'
'HH:MM:SS', 'HH:MM',
value from 0 to 34.
• As a string with no delimiters in
example,
'101112'
minute part) and becomes '00:00:00'.
Date and Time Literals
and
TIMESTAMP
'2012-12-31
'2012@12@31 11^30^45'
'YYYYMMDDHHMMSS'
09:15:28', but
'0000-00-00
00:00:00'.
or
YYYYMMDDHHMMSS
19830905132800
value can include a trailing fractional seconds part in up to microseconds
columns. For information about fractional seconds support in MySQL, see
are converted to 1970-1999.
70-99
are converted to 2000-2069.
00-69
or
YYYYMMDDHHMMSS
and 03, but the day part is completely missing. However,
99
values in these formats:
format. You can also use one of the following "relaxed" syntaxes:
HH', or 'SS'. Here
'D
HH:MM',
'D
format, provided that it makes sense as a time. For
'HHMMSS'
is understood as '10:11:12', but
749
values in these formats:
or
'YY-MM-DD HH:MM:SS'
11:30:45',
are equivalent.
or
'YYMMDDHHMMSS'
'20070523091528'
'071122129015'
format, provided that the number
YYMMDDHHMMSS
and
830905132800
Values".
Dates".
is the same as '2015-06-09'. Similarly,
'2015-6-9'
'2015-10-30 1:2:3'
format and that the year is given by the first 4
YYMMDD
represents days and can have a
D
'109712'
format. A "relaxed"
'2012^12^31
11+30+45',
format, provided
and
'070523091528'
is illegal (it has a nonsensical
are interpreted as
is the same as
or
format and
YYMMDDHHMMSS
is illegal (it has a nonsensical
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers