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:
datetime(timestring, [ modifier1, modifier2, ... modifier_n ] )
Example1: Retrieve current date and time:
SELECT datetime('now');
Output:
Example2: Add/ subtract years to current date and time:
SELECT datetime('2017-04-13','+5 years'); SELECT datetime('now','+5 years');
Output:
Example3: Add/ subtract days to current date and time:
SELECT datetime('2017-04-13','+5 days'); SELECT datetime('now','+5 days'); SELECT datetime('now','-5 days');
Output:
Example4: Add/ subtract hours to current date and time:
SELECT datetime('2017-04-13','+5 hours'); SELECT datetime('now','+5 hours'); SELECT datetime('now','-5 hours');
Output:
Example5: Add/ subtract minutes to current date and time:
SELECT datetime('now','+150 minutes'); SELECT datetime('now','-50 minutes');
Output: