Compare dates (stored as string) in android sqlite database?

if you are storing dates as strings in the format

YYYY-MM-DD HH:mm:ss  

====> then your date field is a DateTime datatype

Thus you have to use such query

select * 
  from MyTable 
  where mydate >= Datetime('2000-01-01 00:00:00') 
  and mydate <= Datetime('2050-01-01 23:00:59')

you can also use the snippet given by @Joop Eggen with th between operator it’s th same approche.

The BETWEEN operator is logically equivalent to a pair of comparisons. “x BETWEEN y AND z” is equivalent to “x>=y AND x<=z” except that with BETWEEN, the x expression is only evaluated once. see sqlite3 docs

Leave a Comment