MYSQL - datetime to seconds

前端 未结 7 1694
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 01:40

I wasn\'t able to find out (googling, reading mysql reference manual) how to get value of DATETIME in seconds in MySQL.

I dont mean to extract secon

7条回答
  •  暖寄归人
    2020-12-09 01:55

    If by "convert to seconds", you mean "convert to an UNIX Timestamp" (i.e. number of seconds since 1970-01-01), then you can use the UNIX_TIMESTAMP function :

    select UNIX_TIMESTAMP(your_datetime_field)
    from your_table
    where ...
    


    And, for the sake of completness, to convert from an Unix Timestamp to a datetime, you can use the FROM_UNIXTIME function.

提交回复
热议问题