CodesJava

Easy learning with example program codes

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:

FORMATDESCRIPTIONVALUES
%YYear0000 to 9999
%WWeek of year00 to 53
%wDay of week0 to 6, where 0 is Sunday
%mMonth of year01 to 12
%dDay of month00 to 31
%HHour00 to 24
%MMinute00 to 25
%SSeconds00 to 59
%sSecondsSince 1970-01-01
%fFractional secondsSS.SSS
%jDay of year001 to 366
%JJulian dayNumeric 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:
error









Copyright © 2019 CodesJava DMCA.com Protection Status