This is very similar to another question that got closed as not a real question. I tried to edit it to make it valid for reopening but was told I would be better off asking a new question.
I'm developing on android and need to store datetime values in a sqlite database to track repeating events that will generate notifications. I will also need to be able to query the database based on time ranges.
The SQLite documentation states that it does not support specific date types but that dates can be represented using TEXT, REAL, or INTEGER types:
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.
The advantages of each initially seem to be:
- TEXT useful for readability in the database with ability to be displayed directly later (no transformation necessary), but costly if calculations need to be performed on them. Introduces possible error from time zones.
- REAL useful for dates before 1970, good for calculations or date comparisons. Does not represent time of day, only days.
- INTEGER useful for calculations or datetime comparisons, very good compatibility since it is a widely supported standard.
Does this sound correct? Would using an INTEGER for datetimes make querying time ranges noticeably faster than when using TEXT? Anything else I haven't considered?
Given my use case, which of these solutions would be best?