I'm trying to insert the current timestamp into SQLite:
CREATE TABLE test (timestamp DATETIME);
INSERT INTO test VALUES(datetime('now'));
This does create the timestamp, but only with seconds-precision (the timestamp looks like 2013-12-17 07:02:20
). Is it possible to add the milliseconds, as well?
First, create a new table named datetime_real . Second, insert the “current” date and time value into the datetime_real table. We used the julianday() function to convert the current date and time to the Julian Day. Third, query data from the datetime_real table.
Precision in time values specifies the number of fractional digits retained in the seconds field. For example, specifying a TIMESTAMPTZ value as TIMESTAMPTZ(3) truncates the time component to milliseconds. By default, TIMESTAMP / TIMESTAMPTZ values have a precision of 6 (microseconds).
MySQL MICROSECOND() function MySQL MICROSECOND() returns MICROSECONDs from the time or datetime expression. The return value is within the range of 0 to 999999.
Date and time functions reference says datetime(timestring, [modifiers...])
is equivalent to strftime('%Y-%m-%d %H:%M:%S', timestring, [modifiers...])
.
If you want fractional seconds you must use %f
not %S
. So use strftime('%Y-%m-%d %H:%M:%f', 'now')
.
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