SQLite datetime Function

The SQLite datetime function is used to retrieve date and time in different format. The result format of datetime function is 'YYYY-MM-DD HH:MM:SS'.

Syntax:

snippet
datetime(timestring, [ modifier1, modifier2, ... modifier_n ] )

Example1: Retrieve current date and time:

snippet
SELECT datetime('now');

Output:

SQLite Datetime function 1

Example2: Add/ subtract years to current date and time:

snippet
SELECT datetime('2017-04-13','+5 years');
SELECT datetime('now','+5 years');

Output:

SQLite Datetime function 2 SQLite Datetime function 3

Example3: Add/ subtract days to current date and time:

snippet
SELECT datetime('2017-04-13','+5 days');
SELECT datetime('now','+5 days');
 SELECT datetime('now','-5 days');

Output:

SQLite Datetime function 4 SQLite Datetime function 5 SQLite Datetime function 6

Example4: Add/ subtract hours to current date and time:

snippet
SELECT datetime('2017-04-13','+5 hours');
SELECT datetime('now','+5 hours');
 SELECT datetime('now','-5 hours');

Output:

SQLite Datetime function 7 SQLite Datetime function 8 SQLite Datetime function 9

Example5: Add/ subtract minutes to current date and time:

snippet
SELECT datetime('now','+150 minutes');
 SELECT datetime('now','-50 minutes');

Output:

SQLite Datetime function 10 SQLite Datetime function 11
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents