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

后端 未结 8 1711
名媛妹妹
名媛妹妹 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:07

    To get the max. Range +/- wise use this query on your birthday field, in my case "yyyy-mm-dd" but you can change it to your needs

    select name, (@bday:=STR_TO_DATE(birthday,"%Y-%m-%d")),if(year(@bday)<1970,UNIX_TIMESTAMP(affffdate(@bday, interval 68 year))-2145916800,UNIX_TIMESTAMP(@bday)) from people
    

提交回复
热议问题