简体   繁体   中英

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?

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');
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM