pratnala
pratnala

Reputation: 3843

Date and time data type in SQLite

I want to store timestamps in my SQLite database and this answer on this question was looking promising. Then, I saw the SQLite documentation which says that there are only 4 data types: TEXT, INTEGER, REAL, BLOB. How do I go about? Also, millisecond precision would be useful though I can manage if it only gives precision upto a second. Also, timezone isn't important.

Upvotes: 0

Views: 2848

Answers (2)

laalto
laalto

Reputation: 152817

Milliseconds or seconds since an epoch in an INTEGER. sqlite INTEGERs support up to 64 bits of storage.

Convert to/from string representations with timezone support in code.

Upvotes: 3

Arjit
Arjit

Reputation: 3456

SQLite does not have a separate storage class for storing dates and/or times, but SQLite is capable of storing dates and times as TEXT, REAL or INTEGER values.

1) TEXT - A date in a format like "YYYY-MM-DD HH:MM:SS.SSS".

2) REAL - The number of days since noon in Greenwich on November 24, 4714 B.C.

3) INTEGER - The number of seconds since 1970-01-01 00:00:00 UTC.

For more details you can visit TutorialsPoint SQLite

Upvotes: 2

Related Questions