sql時間変換レコード

742 ワード

時間-->文字列
select date_format(now(), '%Y-%m-%d %H:%i:%s');
--   :2018-05-02 20:24:10

時間——>タイムスタンプ
select unix_timestamp(now());
--   :1525263383

 
タイムスタンプ——>文字列
select from_unixtime(1525263383, '%Y-%m-%d %H:%i:%s');
--   :2018-05-02 20:24:10

タイムスタンプ——>タイム
select from_unixtime(1525263383);
--   :2018-05-02 20:16:23

 
文字列-->時間
select str_to_date('2018-05-02','%Y-%m-%d %H:%i:%s');
--   :2018-05-02 06:03:21

文字列-->タイムスタンプ
select unix_timestamp('2018-05-02 20:24:10');
--   :1525263383