11.2 Date and Time Data Types日期和时间数据类型

11.2.1 Date and Time Data Type Syntax日期和时间数据类型语法
11.2.2 The DATE, DATETIME, and TIMESTAMP Types日期、日期时间和时间戳类型
11.2.3 The TIME Type时间类型
11.2.4 The YEAR Type年份类型
11.2.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME时间戳和日期时间的自动初始化和更新
11.2.6 Fractional Seconds in Time Values时间值中的小数秒
11.2.7 Conversion Between Date and Time Types日期和时间类型之间的转换
11.2.8 2-Digit Years in Dates日期中的两位数年份

The date and time data types for representing temporal values are DATE, TIME, DATETIME, TIMESTAMP, and YEAR. 用于表示时间值的日期和时间数据类型是DATETIMEDATETIMETIMESTAMPYEAREach temporal type has a range of valid values, as well as a zero value that may be used when you specify an invalid value that MySQL cannot represent. 每个时态类型都有一系列有效值,以及一个“零”值,当您指定MySQL无法表示的无效值时,可以使用该值。The TIMESTAMP and DATETIME types have special automatic updating behavior, described in Section 11.2.5, “Automatic Initialization and Updating for TIMESTAMP and DATETIME”.TIMESTAMPDATETIME类型具有特殊的自动更新行为,如第11.2.5节“TIMESTAMP和DATETIME的自动初始化和更新”所述。

For information about storage requirements of the temporal data types, see Section 11.7, “Data Type Storage Requirements”.有关临时数据类型的存储要求的信息,请参阅第11.7节,“数据类型存储要求”

For descriptions of functions that operate on temporal values, see Section 12.7, “Date and Time Functions”.有关对时间值进行操作的函数的描述,请参阅第12.7节,“日期和时间函数”

Keep in mind these general considerations when working with date and time types:使用日期和时间类型时,请记住以下一般注意事项:

The following table shows the format of the zero value for each type. 下表显示了每种类型的“零”值的格式。The zero values are special, but you can store or refer to them explicitly using the values shown in the table. “零”值是特殊的,但是您可以使用表中显示的值显式地存储或引用它们。You can also do this using the values '0' or 0, which are easier to write. 也可以使用值'0'0来执行此操作,这些值更易于编写。For temporal types that include a date part (DATE, DATETIME, and TIMESTAMP), use of these values may produce warning or errors. 对于包含日期部分(DATEDATETIMETIMESTAMP)的时态类型,使用这些值可能会产生警告或错误。The precise behavior depends on which, if any, of the strict and NO_ZERO_DATE SQL modes are enabled; see Section 5.1.11, “Server SQL Modes”.精确的行为取决于启用了哪种严格和NO_ZERO_DATESQL模式(如果有的话);请参阅第5.1.11节,“服务器SQL模式”

Data Type数据类型 Zero Value“零”值
DATE'0000-00-00'
TIME'00:00:00'
DATETIME'0000-00-00 00:00:00'
TIMESTAMP'0000-00-00 00:00:00'
YEAR0000
11.2.1 Date and Time Data Type Syntax
11.2.2 The DATE, DATETIME, and TIMESTAMP Types
11.2.3 The TIME Type
11.2.4 The YEAR Type
11.2.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME
11.2.6 Fractional Seconds in Time Values
11.2.7 Conversion Between Date and Time Types
11.2.8 2-Digit Years in Dates