How to compare two dates in SQLite?

前端 未结 3 532
孤独总比滥情好
孤独总比滥情好 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条回答
  •  无人共我
    2021-02-07 19:20

    From Datatypes In SQLite Version 3:

    1.2 Date and Time Datatype

    SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

    • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
    • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
    • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

    Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

    If you look at the examples in Date And Time Functions, something like this should get you close to what you want (which, I'm assuming, is 6:00 of the current day):

    WHERE b.start_time = date('now', 'start of day', '+6 hours')
    

提交回复
热议问题