Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix timestamp in sqlite?

How do you obtain the current timestamp in Sqlite? current_time, current_date, current_timestamp both return formatted dates, instead of a long.

sqlite> insert into events (timestamp) values (current_timestamp); sqlite> insert into events (timestamp) values (current_date); sqlite> insert into events (timestamp) values (current_time); sqlite> select * from events; 1|2010-09-11 23:18:38 2|2010-09-11 3|23:18:51 

What I want:

4|23234232 
like image 227
yayitswei Avatar asked Sep 11 '10 23:09

yayitswei


1 Answers

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.

like image 136
Daniel Vassallo Avatar answered Oct 11 '22 20:10

Daniel Vassallo