Converting a date string which is before 1970 into a timestamp in MySQL

后端 未结 8 1704
名媛妹妹
名媛妹妹 2020-12-17 14:51

Not a very good title, so my apologies.

For some reason, (I wasn\'t the person who did it, i digress) we have a table structure where the field type for a date is va

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 15:17

    Aha! We've found a solution!

    The SQL to do it:

    SELECT DATEDIFF( STR_TO_DATE('04-07-1988','%d-%m-%Y'),FROM_UNIXTIME(0))*24*3600 -> 583977600
    SELECT DATEDIFF( STR_TO_DATE('04-07-1968','%d-%m-%Y'),FROM_UNIXTIME(0))*24*3600 -> -47174400 
    

    This could be useful for future reference.

    You can test it here: http://www.onlineconversion.com/unix_time.htm

提交回复
热议问题