Reputation: 1636
I pull data from a websource and it returns time in the format 'YYYY-MM-DDTHH:MM:SS.SSSZ'. Since I would be doing a lot of comparisons on this column, I thought it would be best to store them as the number of millliseconds since epoch (I need millisecond precision!!). What would be the best way to convert the incoming datetime string to number of milliseconds?
I tried to use
strftime('%s', datetimeString)
- gives back the number of seconds since epoch till datetimeString
strftime('%f', datetimeString)
- gives back only the SS.SSS part!!
Upvotes: 1
Views: 1745
Reputation: 33954
I'm guessing it has something to do with SQLite not having actual Date or Datetime types (section 1.2). Instead it formats them as one of:
TEXT
type)REAL
type)INTEGER
type)The REAL
data type may not have enough precision to store a date, time, and fractional seconds in a single field.
It seems the answer is one of:
INTEGER
type in SQLite3)Without switching your DB, and if you never need sub-millisecond precision, then I'd at least try the "manual calculation + single integer column" solution and see if it works.
Upvotes: 2