SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite NOW() Function



In SQLite, there is no now() function, but rather "now" is a time-value parameter that is used in various SQLite functions to retrieve the current date and time. The syntax below shows how to use the "now" parameter with various functions.

Syntax

/* using with DATE() function */
DATE('now');

/* using with TIME() function */
TIME('now');

/* using with DATETIME() function */
DATETIME('now');

/* using with STRFTIME() function */
STRFTIME(format, 'now')

Parameters

format

Required. Specify the format string to format the outputted date and time string when used with strftime() function. It can be one of the following:

FormatDescription
%dDay of the month (1-31)
%fSeconds with fractional seconds (SS.SSS)
%HHour on 24-hour clock (00-23)
%jDay of the year (001-366)
%JJulian day number (fractional)
%mMonth (01-12)
%MMinute (00-59)
%sSeconds since 1970-01-01
%SSeconds (00-59)
%wWeekday (0-6)
(0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday)
%WWeek number in the year (00-53)
%YYear (0000-9999)
%%% as a literal

Example: Current date

In the example below, the SQLite 'now' time-value is used to get the current date.

SELECT DATE('now');
Result: '2022-04-12'

SELECT STRFTIME('%Y-%m-%d', 'now');
Result: '2022-04-12'

Example: Current time

Similarly, it can be used to get the current time.

SELECT TIME('now');
Result: '06:08:59'

SELECT STRFTIME('%H-%M-%S', 'now');
Result: '06-08-59'

SELECT STRFTIME('%H-%M-%f', 'now');
Result: '06-08-59.187'

SELECT STRFTIME('%H-%M', 'now');
Result: '06-08'

Example: Current date and time

It can also be used to get the current date and time as shown below:

SELECT DATETIME('now');
Result: '2022-04-12 06:08:59'

SELECT STRFTIME('%Y-%m-%d %H-%M', 'now');
Result: '2022-04-12 06-08'

SELECT STRFTIME('%Y-%m-%d %H-%M-%S', 'now');
Result: '2022-04-12 06-08-59'

SELECT STRFTIME('%Y-%m-%d %H-%M-%f', 'now');
Result: '2022-04-12 06-08-59.187'

❮ SQLite Functions