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

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

    At best you will have mixed results depending on the system you are using to represent the timestamp.

    From wikipedia

    There was originally some controversy over whether the Unix time_t should be signed or unsigned. If unsigned, its range in the future would be doubled, postponing the 32-bit overflow (by 68 years). However, it would then be incapable of representing times prior to 1970. Dennis Ritchie, when asked about this issue, said that he hadn't thought very deeply about it, but was of the opinion that the ability to represent all times within his lifetime would be nice. (Ritchie's birth, in 1941, is around Unix time −893 400 000.) The consensus is for time_t to be signed, and this is the usual practice. The software development platform for version 6 of the QNX operating system has an unsigned 32-bit time_t, though older releases used a signed type.

    It appears that MySQL treats timestamps as an unsigned integer, meaning that times before the Epoc will all resolve to 0.

    This being the case, you always have the option to implement your own unsigned timestamp type and use that for your calculations.

    0 讨论(0)
  • 2020-12-17 15:22

    I have not tried the above solutions but this might in case you are not able to retrieve the date value from the MySQL database in the form of timestamp, then this operation can also be tried

    SELECT TIMESTAMPDIFF(second,FROM_UNIXTIME(0),'1960-01-01 00:00:00');

    0 讨论(0)
提交回复
热议问题