Unix timestamp in sqlite? Unix timestamp in sqlite? sqlite sqlite

Unix timestamp in sqlite?


The docs mention this method:

SELECT strftime('%s', 'now');1284248196

And this one which includes the fractional part:

SELECT (julianday('now') - 2440587.5) * 86400.0;1284248196.65098

Both represent Unix Time, the number of seconds passed since January 1, 1970.


select strftime('%W'),date('now'),date(),datetime(),strftime('%s', 'now');

result in

strftime('%W')  -   date('now')  -  date()   -  datetime()   -     strftime('%s', 'now')    08       -      2021-02-23   -  2021-02-23 - 2021-02-23  15:35:12-  1614094512


For some reason (that's undoubtedly my fault) Daniel's julianday() component doesn't quite do it for me, but resorting to the following jankery appears to do the trick when selecting from a timestamp field called tmstmp:

select strftime('%s', a.tmstmp) + strftime('%f', a.tmstmp)   as unix_timefrom any_table a