search

Home  >  Q&A  >  body text

mysql函数unix_timestamp如何处理1970.1.1以前的数据?

高洛峰高洛峰2902 days ago785

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 16:12:09

    Then there is no way to use TIMESTAMP
    You can consider using the DATETIMEtype

    DATE range '1000-01-01' to '9999-12-31'

    DATETIME'1000-01-01 00:00:00' to '9999-12-31 23:59:59'

    TIMESTAMP '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC

    reply
    0
  • PHPz

    PHPz2017-04-17 16:12:09

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    <code>-- N秒前

    SELECT TIMESTAMPADD(SECOND,-3600,'1970-01-01 00:00:01')

    -- >> 1969-12-31 23:00:01

     

    -- 2天前

    SELECT TIMESTAMPADD(DAY,-2,'1970-01-01 00:00:01')

    -- >> 1969-12-30 00:00:01

     

    # FRAC_SECOND。表示间隔是毫秒

    # SECOND。秒

    # MINUTE。分钟

    # HOUR。小时

    # DAY。天

    # WEEK。星期

    # MONTH。月

    # QUARTER。季度

    # YEAR。年</code>

    Make sure the negative number you save is relative to 1970-01-01 00:00:01, there is no problem in this calculation

    1

    <code>select TIMESTAMPADD(FRAC_SECOND, table.create_time, '1970-01-01 00:00:01') as `create_time` from table</code>

    reply
    0
  • Cancelreply