Home  >  Q&A  >  body text

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

高洛峰高洛峰2743 days ago709

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

    -- 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。年

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

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

    reply
    0
  • Cancelreply