fullstack_webdev

Code and notes from Full stack web developer path, LinkedIn Learning.

View on GitHub

7. Dates and Times

07_01 Dates and Times in SQL: Overview

-- Return the timestamp, current date and time in UTC timezone
SELECT DATETIME('now','localtime'); -- Return time and date for local time zone
SELECT DATETIME('now');

-- Return date
SELECT DATE('now','localtime'); -- Just the date
SELECT DATE('now');

-- Return time
SELECT TIME('now'); -- Just the time

SELECT DATETIME('now', '+1 day'); -- Current DateTime + 1 Day
SELECT DATETIME('now', '+3 days'); -- Current + 3 days
SELECT DATETIME('now', '-1 month');-- And so on
SELECT DATETIME('now', '+1 year');
-- Combine multiple arguments for more complex calculations
SELECT DATETIME('now', '+3 hours', '+27 minutes', '-1 day', '+3 years');