i have sqlite database has looks like:
timestamp user action ------------------------------ 1236643200 john abc 1236711411 bob abc 1236711516 bob abc 1236711518 sarah abc 1236711519 john abc
i want search date range 08/15/2016-09/30/2016
. elegant way of doing that?
this not work:
select * events (timestamp between 09/30/2016 , 08/15/2016)
and because timestamps stored integers. how can convert 09/30/2016
epoch timestamp before doing search? tried using strftime
, there many options can't want it?
sqlite
can understand dates of form yyyy-mm-dd
. example:
sqlite> select strftime('%s','2016-09-30'); 1475193600
if don't have date in form, have convert first:
sqlite> select strftime('%s',substr('09/30/2016',7,4) || '-' || substr('09/30/2016',1,2) || '-' || substr('09/30/2016',4,2)); 1475193600
note, if working date range, might have add 1 day upper bound of range ensure includes last day in entirety. have that:
select * events timestamp between strftime('%s','2016-08-15') , strftime('%s','2016-09-30','1 day')
Comments
Post a Comment