How to compare two dates in SQLite?

前端 未结 3 541
孤独总比滥情好
孤独总比滥情好 2021-02-07 18:39

I kind of assumed it was a string, so I compared it as a string, but not surprisingly it failed. I believe thats how it works in Mysql. I could be wrong as I haven\'t worked on

3条回答
  •  旧时难觅i
    2021-02-07 19:32

    Sqlite can not compare dates directly. we need to convert them in seconds as well as integer also.

    Example

    SELECT * FROM Table  
    WHERE  
    CAST(strftime('%s', date_field)  AS  integer) <=CAST(strftime('%s', '2015-01-01')  AS  integer) ;
    

提交回复
热议问题