now() function in SQLite

SQLite now()
Now” is a time string parameter in SQLite which is used to fetch the current date and time by various SQLite functions.

Syntax 1:

date('now')   

Syntax 2:

time('now')   

Syntax 3:

strftime('%Y-%m-%d','now')  

Syntax 4:

strftime('%Y-%m-%d %H-%M','now')  

Syntax 5:

strftime('%Y-%m-%d %H-%M-%S','now')  

Format:

FORMAT DESCRIPTION VALUES
%Y Year 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 Numeric value

Example1:

SELECT date('now');

Output:

2019-08-05

Explanation:
In the above example, we are retrieving the current date.

Example 2:

SELECT date('now', 'start of month');

Output:

2019-08-01

Explanation:
In the above example, we are retrieving the first day of the month.

Example 3:

SELECT date('now', 'start of month','+1 month', '-1 day');

Output:

2019-08-31

Explanation:
In the above example, we are retrieving the last day of the month.

Example 4:

SELECT date('now','+2 years');

Output:

2021-08-05

Explanation:
In the above example, we are adding 2 years to the current date.

Example 5:

SELECT date('now','+2 days');

Output:

2019-08-07

Explanation:
In the above example, we are adding 2 days to the current date.

Example 6:

SELECT date('now','-2 days');

Output:

2019-08-03

Explanation:
In the above example, we are subtracting 2 days from the current date.

Example 7:

SELECT datetime('now');

Output:

2019-08-05 12:00:07

Explanation:
In the above example, we are retrieving the current date and time.

Example 8:

SELECT julianday('now');

Output:

2458700.5

Explanation:
In the above example, we are retrieving the current date.

Example 9:

SELECT strftime('%Y %m %d', 'now');

Output:

2019-08-05

Explanation:
In the above example, we are retrieving the current date.
 

Please Share