MySQL time, string, timestamp convert each other

time to string

  • select date_format(now(), ‘%Y-%m-%d’);
    结果:2018-05-02

time to timestamp

  • select unix_timestamp(now());
    result: 1525263383

String to time

  • select str_to_date('2018-05-02', '%Y-%m-%d %H');
    result: 2018-05-02 00:00:00

String to Timestamp

  • select unix_timestamp('2018-05-02');
    result: 1525263383

Timestamp to time

  • select from_unixtime(1525263383);
    result: 2018-05-02 20:16:23

Timestamp to string

  • select from_unixtime(1525263383,'%Y-%d');
    result: 2018-02

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325213416&siteId=291194637