SQLite3 - convert human date to epoch

妖精的绣舞 提交于 2020-07-23 09:01:16

问题


I have dates in US format, and my database supports epoch (unixtime). Is it possible to convert using the SQLite3 query?

INSERT INTO candles_USD_BCH (id, timestamp) values (null, 2018-03-31 01:02:03);

回答1:


INSERT INTO candles_USD_BCH (id, timestamp) 
  values (null, CAST(strftime('%s', '2018-03-31 01:02:03') as integer));

The CAST() is probably not essential in SQLite, but I think it's a good habit. The function strftime() returns a string.

SQLite Date and Time functions, and pay attention to the section "Caveats and Bugs".



来源:https://stackoverflow.com/questions/49939959/sqlite3-convert-human-date-to-epoch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!