问题
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