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

后端 未结 5 1097
不知归路
不知归路 2020-12-02 19:03

I store dates as String in my database, in this format:

YYYY-MM-DD HH:MM:SS

which is one of supported formats (http://www.sqli

5条回答
  •  庸人自扰
    2020-12-02 19:42

    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

提交回复
热议问题