sqlite: how to select current_timestamp as millisecond value since 1/1/1970

2.3k Views Asked by At
sqlite> select typeof(date('now'));
text
sqlite> select typeof(current_time);
text
sqlite> select typeof(current_date);
text

How to select the current date/time as an integer value of milliseconds since Jan/1/1970?

3

There are 3 best solutions below

2
On BEST ANSWER

strftime() gives you only seconds:

SELECT strftime('%s', 'now') * 1000;
0
On
SELECT unixepoch('subsec');

The "subsecond" and "subsec" modifiers have the special property that they can occur as the first argument to date/time functions (or as the first argument after the format string for strftime()). When this happens, the time value that is normally in the first argument is understood to be "now". For example, a short cut to get the current time in seconds since 1970 with millisecond precision is to say:

1
On

From SQLite doc:

Compute the time since the unix epoch in seconds (like strftime('%s','now') except includes fractional part):

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

DBFiddle Demo