LQ
SQL Reference
Practice →
SQL ReferenceFunctionsDate & Time

Date & Time

Work with dates, times, and timestamps.

Questions this answers
  • How do I get today's date?
  • How do I extract the year or month from a date?
  • How do I filter rows by date range?
  • How do I format a date for display?

How it works

Date functions let you extract parts of a date, compare dates, and format them. The exact functions vary by database — SQLite uses strftime, PostgreSQL uses EXTRACT and date_trunc, MySQL has its own set.

Get current date

SELECT date('now');         -- SQLite
SELECT CURRENT_DATE;        -- SQL standard

Extract year, month, day

-- SQLite
SELECT strftime('%Y', created_at) AS year,
       strftime('%m', created_at) AS month
FROM orders;

Filter by date range

SELECT * FROM orders
WHERE created_at >= '2024-01-01'
  AND created_at < '2025-01-01';
💡 Store dates in ISO format (YYYY-MM-DD) so string comparison works correctly.

Ready to practise Date & Time?

Solve real exercises with AI feedback — free to start.

Try it free →