Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Order By Date1530019888000

Every record in my SQLite database contains a field which contains a Date stored as a string in the format 'yyyy-MM-dd HH:mm:ss'.

Is it possible to query the database to get the record which contains the most recent date please?

like image 211
duncanportelli Avatar asked Dec 30 '12 13:12

duncanportelli


3 Answers

you can do it like this

SELECT * FROM Table ORDER BY date(dateColumn) DESC Limit 1
like image 89
Paritosh Avatar answered Oct 17 '22 05:10

Paritosh


For me I had my query this way to solve my problem

select *  from Table order  by datetime(datetimeColumn) DESC LIMIT 1

Since I was storing it as datetime not date column

like image 44
Ahmad Baraka Avatar answered Oct 17 '22 06:10

Ahmad Baraka


When you sure the format of text field is yyyy-MM-dd HH:mm:ss (ex.: 2017-01-02 16:02:55), So It works for me simply:

SELECT * FROM Table ORDER BY dateColumn DESC Limit 1

Without any extra date function!

like image 11
Nabi K.A.Z. Avatar answered Oct 17 '22 07:10

Nabi K.A.Z.