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(

Syntax 4:

strftime(

Syntax 5:

strftime(

Format:

FORMAT DESCRIPTION VALUES
Year 0000 to 9999
Week of year 00 to 53
Day of week 0 to 6, where 0 is Sunday
Month of year 01 to 12
Day of month 00 to 31
Hour 00 to 24
Minute 00 to 25
Seconds 00 to 59
Seconds Since 1970-01-01
Fractional seconds SS.SSS
Day of year 001 to 366
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 follow and like us:
Content Protection by DMCA.com