lacas
lacas

Reputation: 14067

SQLite query between dates

select * from table_my where my_date between '2014-07-23 00:00:00' and '2014-07-30 00:00:00' order by _id desc

Here is my query, I d like to create this simple date compare query, but not working. This query don't add anything out. Why? How can I compare dates in sqlite?

Upvotes: 0

Views: 122

Answers (2)

ngrashia
ngrashia

Reputation: 9904

Try below query using strftime date functions.

SELECT * from table_my
WHERE strftime('%Y-%m-%d', my_date )
     between  
          strftime('%Y-%m-%d', '2014-07-23') 
          and 
          strftime ('%Y-%m-%d', '2014-07-30');

EDIT:

To use with hours and minutes, you can try something like:

SELECT * from table_my
WHERE strftime('%Y-%m-%d  %H:%M', my_date )
     between  
          strftime('%Y-%m-%d  %H:%M', '2014-07-23 11:22') 
          and 
          strftime ('%Y-%m-%d  %H:%M', '2014-07-23 11:25');

Upvotes: 2

select * from table_my where my_date between '2014-07-30' and '2014-07-23' order by _id desc

use above query may it will work to you i also got such kind of problem during coding i think it is coming cause your using lower value before greater value

may it will help you just chek it

i just swiped the two dates also i removed timestamp

Upvotes: 0

Related Questions