The documentation for SQLite3 datatypes says
the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values
I want to use those functions to store INTEGER
values. How do I do so? The documentation for SQLite3 datetime functions describes the types of the arguments to those functions, but says nothing of the return type. It seems that the return type is text
:
sqlite> select typeOf(datetime('2014-12-12 12:12:12.000'));
text
This is not what I want -- I want an integer value representing that time as a UNIX timestamp. Even when I create a column of type integer
and attempt to store a datetime(...)
value in it, SQLite stores it as a text
value in that integer
column.
How do I force the datetime
function and friends to return a UNIX timestamp, instead of a text
value?
Date and Time Datatype. SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values: TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.
The date() function returns the date as text in this format: YYYY-MM-DD. The time() function returns the time as text in this format: HH:MM:SS. The datetime() function returns the date and time as text in their same formats: YYYY-MM-DD HH:MM:SS.
All the built-in date/time functions return strings.
To convert a string into a number, use CAST:
SELECT CAST(strftime('%s', 'now') AS INT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With