DATETIME and TIMESTAMP Length/Values Error

前端 未结 1 776
南方客
南方客 2021-01-06 01:24

I was using int type for storing datetime type data. For the convenience of getting the data in specific range from MySQL, I tried changing it to TIMESTAM

相关标签:
1条回答
  • 2021-01-06 02:17

    When defining a DATETIME or TIMESTAMP field, there's no need to specify the length.

    This is what the error message refers to:

    A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision

    MySQL permits fractional seconds 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));
    

    Abstract from CREATE TABLE Syntax:

    | TIME[(fsp)]
    | TIMESTAMP[(fsp)]
    | DATETIME[(fsp)]
    

    Documentation:

    • The DATE, DATETIME, and TIMESTAMP Types
    • Date and Time Type Overview
    0 讨论(0)
提交回复
热议问题