Excel to SQL · Lesson 12 of 12

Dates: months, weeks and days between

In Excel, you'd reach for
fx=TEXT(A2,"yyyy-mm"), =WEEKNUM(), =B2-A2, =DATEDIF()

Dates in this database are text like 2026-03-14. SQLite has a few small tools for them:

  • strftime('%Y-%m', d) gives the month, like =TEXT(d, "yyyy-mm")
  • date(d, 'weekday 0', '-6 days') gives the Monday that starts that week
  • julianday(b) - julianday(a) gives the days between two dates
  • date(d, '+1 month') adds a month, like =EDATE()
Try itEdit the query, then Run
monthsignups
2026-0148
2026-0252
2026-0375
2026-0465
2026-0596
2026-0684

6 rows

Every database names these differently. In Postgres or Snowflake it's date_trunc('month', d); in BigQuery, DATE_TRUNC(d, MONTH). If you understand "cut the date down to its month, then group", you can look up the spelling anywhere.

Your turn

How many orders were placed in each month? Show month (like 2026-03) and orders, in date order.

This page on one card

Dates: months, weeks and days between: the Excel way (=TEXT(A2,"yyyy-mm")) and the SQL query, side by side
Dates: months, weeks and days between, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows