mysql的TIMESTAMP多支持6位小数(微秒)

2020-07-03 00:00:00 专区 订阅 付费 陋室 不在

ADATETIMEorTIMESTAMPvalue can include a trailing fractional seconds part in up to microseconds (6 digits) precision. In particular, any fractional part in a value inserted into aDATETIMEorTIMESTAMPcolumn is stored rather than discarded. With the fractional part included, the format for these values is'YYYY-MM-DD hh:mm:ss[.fraction]', the range forDATETIMEvalues is'1000-01-01 00:00:00.000000'to'9999-12-31 23:59:59.999999', and the range forTIMESTAMPvalues is'1970-01-01 00:00:01.000000'to'2038-01-19 03:14:07.999999'. The fractional part should always be separated from the rest of the time by a decimal point; no other fractional seconds delimiter is recognized.

MySQL has fractional seconds support for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision。

  • To define a column that includes a fractional seconds part, use the syntax type_name(fsp), where type_name is TIME, DATETIME, or TIMESTAMP, and fsp is the fractional seconds precision. For example:
    CREATE TABLE t1 (t TIME(3), dt DATETIME(6));
    The fsp value, if given, must be in the range 0 to 6. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0. (This differs from the standard SQL default of 6, for compatibility with previous MySQL versions.)

相关文章