问题
SQLite doesn't support DATE/DATETIME data type. Therefore datetime can be presented in database as unix timestamp e.g. integer, number of seconds since Jan 01 1970 or as IS0-8601 string
YYYY-MM-DD HH:MM:SS
When datetime is stored as unix timestamp we can perform queries like this:
select * from table where c1 < datetime(1452598502, 'unixepoch', 'localtime')
Also if date is stored as string in the form:
2016-01-10 15:44:42
queries like upper are still correctly executed (lexicographical comparison on the strings will match datetime comparison).
select * from table where c1 < '2016-01-10 15:43:52'
Futher more unix timestamp has max value year 2038, afterthat it's overflow. YYYY has maximum date 9999. Both have a max value. Is there any advantage one over another? I just can't seem to prefer one over another. Maybe I prefer datetime as string YYYY-MM-DD HH:mm:ss as it has max value greater than unixtimestamp.
回答1:
Unix timestamps overflow in the year 2038 only if they are stored as 32-bit values. SQLite supports 64-bit values.
A single number requires less storage space than a string (but this matters only if you have a very large number of records). You have to balance this against the easier debuggability of strings.
来源:https://stackoverflow.com/questions/34742778/unix-timestamp-or-is0-8601-date-string-in-sqlite