This SQLite post explains how to use the SQLite now function (ie: timestring parameter) with syntax and examples.
In SQLite, there isn't a function called the now function, but rather "now" is a timestring parameter that is used in various SQLite functions to retrieve the current date and time. This may seem a bit confusing at first, since other SQL databases have a built-in function whose purpose is to return the current date and time. SQLite does this differently.
We will cover 3 syntaxes that show how to use the "now" timestring in SQLite.
The syntax for the now function (ie: timestring parameter) in SQLite is:
OR
OR
It is used when expressing the current date/time using the strftime function. It can be one or more of the following:
format | Explanation |
---|---|
%Y | Year as 4 digits (0000 to 9999) |
%W | Week of year (00 to 53) |
%w | Day of week (0 to 6, where 0 is Sunday) |
%m | Month of year (01 to 12) |
%d | Day of month (00 to 31) |
%H | Hour (00 to 24) |
%M | Minute (00 to 25) |
%S | Seconds (00 to 59) |
%s | Seconds since 1970-01-01 |
%f | Fractional seconds (SS.SSS) |
%j | Day of year (001 to 366) |
%J | Julian day as a numeric value |
The now function can be used in the following versions of SQLite:
Let's look at some SQLite now function examples and explore how to use the now function in SQLite. You can use the built-in functions to retrieve the current date, current time, or current date/time values.
You could retrieve the current date in SQLite using the "now" timestring with either the date function or strftime function as follows:
You could retrieve the current time in SQLite using the "now" timestring with either the time function or strftime function as follows:
You could retrieve the current date and time in SQLite using the "now" timestring with the strftime function as follows: