Hướng dẫn mysql datetime 3
9.1.3 Date and Time Literals Date and time values can be represented in several formats, such as quoted strings or as numbers, depending on the exact type of the value and other factors. For example, in contexts where MySQL expects a date, it interprets any of This section describes the acceptable formats for date and time literals. For more information about the temporal data types, such as the range of permitted values, see Section 11.2, “Date and Time Data Types”. Standard SQL and ODBC Date and Time LiteralsStandard SQL requires temporal literals to be specified using a type keyword and a string. The space between the keyword and string is optional.
MySQL recognizes but, unlike standard SQL, does not require the type keyword. Applications that are to be standard-compliant should include the type keyword for temporal literals. MySQL also recognizes the ODBC syntax corresponding to the standard SQL syntax:
MySQL uses the type keywords and the ODBC constructions to produce String and Numeric Literals in Date and Time Context MySQL recognizes
MySQL recognizes
A Dates containing two-digit year values are ambiguous because the century is unknown. MySQL interprets two-digit year values using these rules:
See also Section 11.2.8, “2-Digit Years in Dates”. 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 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 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 MySQL recognizes
A trailing fractional seconds part is
recognized in the For Beginning with MySQL 8.0.19, you can specify a time zone offset when inserting
The value inserted must not have a zero for the month part, the day part, or both parts. This is enforced beginning with MySQL 8.0.22, regardless of the server SQL mode setting. This example illustrates inserting datetime values with time zone offsets
into
The offset is not displayed when selecting a datetime value, even if one was used when inserting it. The range of supported offset values is Datetime literals that include time zone offsets are accepted as parameter values by prepared statements. |