Reputation: 16656
I'm aware that there is another similar question on this topic, but personally I am not satisfied with the accepted answer, so this question also asks for an explanation to justify the preferred method. The accepted answer said that the "recommended practice to use a text field to store dates within SQL lite," but this does not make sense to me. I'm not knowledgeable enough to counter with a more definitive answer, but it is my understanding that strings use more memory and are more computationally more difficult to handle than integers. Would it not be better to use Unix timestamps (stored as integers), instead of text to store dates/time? Is not, what IS the downside to using Unix timestamps, compared to text?
Upvotes: 3
Views: 1198
Reputation: 29925
Personally I wouldn't worry all that much. I always use ints with unix timestamps, you're right they'll use less memory. Also they're pretty self explanatory, but only precise to seconds, nothing more. If you need something more precise (milliseconds etc) then you need to get creative.
However storing as plain text is fine, SQLite doesn't have the functionality to store datetime, so the three options suggested at http://www.sqlite.org/datatype3.html#datetime are TEXT, REAL and INT
.
Given that these are the ways they actually tell you to store dates and time, and given that there is no official word on which is preferable, I wouldn't worry too much. Choose what you are comfortable with and which suits your needs best.
Upvotes: 4