Does MySQL support historical date (like 1200)?

前端 未结 7 1565
一整个雨季
一整个雨季 2020-11-30 11:18

I can\'t see any info about that. Where can I find the oldest date Mysql can support ?

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 11:49

    Use SMALLINT for year, so the year will accept from -32768 (BC) to 32768 (AD) As for months and days, use TINYINT UNSIGNED

    Most historical events dont have months and days, so you could query like this :

    SELECT events FROM history WHERE year='-4990'
    

    Result : 'Noah Ark'

    Or : SELECT events FROM history WHERE year='570' AND month='4' AND day='20' return : "Muhammad pbuh was born"

    Depending on requirements, you could also add DATETIME column and make it NULL for date before 1000 and vice versa (thus saving some bytes)

提交回复
热议问题