Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Sqlite query, Get a Date from stored milliseconds [duplicate]

I am using sqlite database in my application in which I am storing a Date and Time in milli-seconds. Now using Sqlite query I am trying to get this datetime from milliseconds to date in format "yyyy-MM-dd" but not getting a proper result.

I want to do this using a Sqlite query. Your help will be appreciated.

like image 784
Dharmendra Avatar asked Aug 28 '12 11:08

Dharmendra


2 Answers

Datetime expects epochtime, which is in number of seconds while you are passing in milliseconds. Convert to seconds & apply.

SELECT datetime(1346142933585/1000, 'unixepoch');

Can verify this from this fiddle

  • http://sqlfiddle.com/#!5/d41d8/223
like image 110
Sathyajith Bhat Avatar answered Oct 14 '22 19:10

Sathyajith Bhat


Try:

select strftime("%Y-%m-%d", YOUR_DATE_COL) from .......
like image 23
Vyacheslav Shylkin Avatar answered Oct 14 '22 20:10

Vyacheslav Shylkin