Date Arithmetic in SQL: Adding Intervals and Measuring Differences
How to calculate with dates in SQL: adding days, months and years, what happens at the end of a month, differences in days, hours, months and years, AGE, working days, deadlines, overlapping periods, date ranges in WHERE, and DATEADD, DATEDIFF and their equivalents in each database.
kvi5hnuCode Sprout team member10 min readOn this page
"Due in 30 days." "Three working days to dispatch." "How long since the last order?" "How old is this customer?" "Do these two bookings clash?" Date arithmetic answers all of these, and it's full of small traps: months have different lengths, "the number of months between two dates" has more than one meaning, and every database spells the functions differently.
This article covers adding to dates, measuring differences, working days, overlapping periods and date ranges in queries. Article 39 introduced the types, and article 41 covers calendars and date series.
Adding and subtracting
-- Adding and subtracting days, and the difference between two dates
SELECT DATE '2026-03-05' + 30 AS plus_30_days,
DATE '2026-03-05' - 7 AS minus_a_week,
DATE '2026-12-25' - DATE '2026-03-05' AS days_between,
pg_typeof(DATE '2026-12-25' - DATE '2026-03-05') AS difference_type;
-- Intervals: months and years follow the calendar
SELECT DATE '2026-03-05' + INTERVAL '1 month' AS plus_month,
DATE '2026-03-05' + INTERVAL '1 year 2 months' AS plus_year_2_months,
DATE '2026-01-31' + INTERVAL '1 month' AS jan_31_plus_month,
DATE '2028-01-31' + INTERVAL '1 month' AS jan_31_leap_year,
DATE '2026-03-31' - INTERVAL '1 month' AS mar_31_minus_month;
plus_30_days | minus_a_week | days_between | difference_type
--------------+--------------+--------------+-----------------
2026-04-04 | 2026-02-26 | 295 | integer
(1 row)
plus_month | plus_year_2_months | jan_31_plus_month | jan_31_leap_year | mar_31_minus_month
---------------------+---------------------+---------------------+---------------------+---------------------
2026-04-05 00:00:00 | 2027-05-05 00:00:00 | 2026-02-28 00:00:00 | 2028-02-29 00:00:00 | 2026-02-28 00:00:00
(1 row)
In PostgreSQL:
date + integeradds days, anddate - integersubtracts them.date - datereturns the number of days between them, as an integer: 295 days from 5 March to Christmas.date + INTERVAL '...'adds an interval of any size:'1 month','1 year 2 months','3 hours'. The result is atimestamp. Cast it back withCAST(... AS date)if you need a date.
Days and hours have fixed lengths, but months and years don't, so adding them follows the calendar. Adding a month moves to the same day of the next month. When that day doesn't exist, as for 31 January plus a month, PostgreSQL uses the last day of the month: 28 February in 2026, 29 February in the leap year 2028. Subtracting a month from 31 March gives 28 February the same way.

This clamping has consequences:
- Month arithmetic isn't reversible: 31 January + 1 month − 1 month is 28 January.
- Adding 1 month twice can differ from adding 2 months: 31 January + 1 month + 1 month is 28 March, while 31 January + 2 months is 31 March.
- For monthly schedules such as billing dates, compute each date from the original date (
start + n * INTERVAL '1 month') rather than from the previous one, so a subscription that started on the 31st returns to the 31st whenever the month allows.
Other databases:
| Database | Add | End of month |
|---|---|---|
| MySQL | DATE_ADD(d, INTERVAL 1 MONTH) or d + INTERVAL 1 MONTH | clamps: 28 Feb |
| SQL Server | DATEADD(month, 1, d) | clamps: 28 Feb |
| Oracle | ADD_MONTHS(d, 1), d + 30 for days | clamps, and from a month's last day always gives the next month's last day. d + INTERVAL '1' MONTH raises an error for 31 Jan |
| SQLite | date(d, '+1 month'), date(d, '+30 days') | overflows: 31 Feb becomes 3 Mar. Add 'floor' (3.43+) to clamp |
Differences between timestamps
-- Subtracting timestamps gives an interval
SELECT TIMESTAMP '2026-03-08 17:45' - TIMESTAMP '2026-03-05 09:15' AS elapsed,
EXTRACT(EPOCH FROM TIMESTAMP '2026-03-08 17:45'
- TIMESTAMP '2026-03-05 09:15') / 3600 AS hours,
ROUND(EXTRACT(EPOCH FROM TIMESTAMP '2026-03-08 17:45'
- TIMESTAMP '2026-03-05 09:15') / 86400, 2) AS days_decimal;
-- AGE: the difference in years, months and days
SELECT AGE(DATE '2026-03-05', DATE '1990-07-20') AS age_parts,
EXTRACT(YEAR FROM AGE(DATE '2026-03-05', DATE '1990-07-20')) AS whole_years,
AGE(DATE '2026-03-31', DATE '2026-01-31') AS two_months;
elapsed | hours | days_decimal
-----------------+---------------------+--------------
3 days 08:30:00 | 80.5000000000000000 | 3.35
(1 row)
age_parts | whole_years | two_months
-------------------------+-------------+------------
35 years 7 mons 16 days | 35 | 2 mons
(1 row)
- Subtracting two timestamps gives an interval: 3 days 08:30.
- To get a number, take the interval's epoch, its length in seconds, and divide: by 3,600 for hours (80.5) or 86,400 for days (3.35).
AGE(later, earlier)returns the difference in years, months and days, calendar-aware: someone born on 20 July 1990 is 35 years, 7 months and 16 days old on 5 March 2026, andEXTRACT(YEAR FROM AGE(...))gives the age in whole years.AGE(d)with one argument measures from the current date.
Computing someone's age as (today - birth_date) / 365 is wrong around birthdays, because of leap years. AGE handles them correctly.
Differences in months and years
"How many months between two dates?" has two common answers:
-- Whole months between dates: two common definitions
SELECT start_d, end_d,
(EXTRACT(YEAR FROM end_d) - EXTRACT(YEAR FROM start_d)) * 12
+ EXTRACT(MONTH FROM end_d) - EXTRACT(MONTH FROM start_d) AS month_boundaries_crossed,
EXTRACT(YEAR FROM AGE(end_d, start_d)) * 12
+ EXTRACT(MONTH FROM AGE(end_d, start_d)) AS complete_months
FROM (VALUES (DATE '2026-01-31', DATE '2026-02-01'),
(DATE '2026-01-15', DATE '2026-03-14'),
(DATE '2026-01-15', DATE '2026-03-15')) AS t(start_d, end_d);
start_d | end_d | month_boundaries_crossed | complete_months
------------+------------+--------------------------+-----------------
2026-01-31 | 2026-02-01 | 1 | 0
2026-01-15 | 2026-03-14 | 2 | 1
2026-01-15 | 2026-03-15 | 2 | 2
(3 rows)
- Month boundaries crossed: the difference in year × 12 + month, ignoring the days. 31 January to 1 February crosses one boundary, so it counts 1, although only one day passed. This is how SQL Server's
DATEDIFFworks for every unit:DATEDIFF(year, '2026-12-31', '2027-01-01')is 1. - Complete months: how many whole months fit between the dates, from
AGE. 15 January to 14 March is 1 complete month, and 15 January to 15 March is 2. This is how MySQL'sTIMESTAMPDIFF(MONTH, a, b)and Oracle'sTRUNC(MONTHS_BETWEEN(b, a))work.
Neither is wrong, but they answer different questions: "which calendar month is this, relative to that one?" versus "how long has it been?". Choose deliberately, and remember that DATEDIFF in SQL Server always counts boundaries. DATEDIFF(day, ...) counts midnights crossed, and DATEDIFF(hour, ...) counts hour boundaries.
| Database | Days | Hours | Complete months |
|---|---|---|---|
| PostgreSQL | d2 - d1 | EXTRACT(EPOCH FROM t2 - t1) / 3600 | from AGE(d2, d1) |
| MySQL | DATEDIFF(d2, d1) | TIMESTAMPDIFF(HOUR, t1, t2) | TIMESTAMPDIFF(MONTH, d1, d2) |
| SQL Server | DATEDIFF(day, d1, d2) | DATEDIFF(hour, t1, t2) (boundaries) | no direct function |
| Oracle | d2 - d1 (may include a fraction) | (t2 - t1) * 24 for dates | MONTHS_BETWEEN(d2, d1) |
| SQLite | julianday(d2) - julianday(d1) | the same × 24 | timediff(d2, d1) (3.43+), a text '+YYYY-MM-DD HH:MM:SS' difference |
Note the argument order: MySQL's DATEDIFF(later, earlier) but SQL Server's DATEDIFF(unit, earlier, later).
Working days and deadlines
Business rules often count working days: "dispatch within 3 working days", "the invoice is due 10 working days after issue". A generated series of dates (article 41) makes these straightforward:
CREATE TABLE products (
product_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
category VARCHAR(20) NOT NULL,
brand VARCHAR(20),
price DECIMAL(8, 2) NOT NULL,
stock INTEGER NOT NULL,
weight_g INTEGER
);
INSERT INTO products VALUES
(1, 'Ridge 2 tent', 'tents', 'Alpina', 249.99, 12, 2100),
(2, 'Summit 4 tent', 'tents', 'Alpina', 489.00, 3, 4300),
(3, 'Glow head torch', 'lighting', 'Lumen', 34.50, 40, 90),
(4, 'Basecamp lantern', 'lighting', NULL, 27.00, 15, NULL),
(5, 'Trail 30 backpack', 'packs', 'Kestrel', 89.95, 22, 1150),
(6, 'Day 18 backpack', 'packs', 'Kestrel', 54.00, 0, 640),
(7, 'Merino socks', 'clothing', 'Woolly', 16.00, 75, 80);
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
city VARCHAR(30),
referred_by INTEGER REFERENCES customers (customer_id)
);
INSERT INTO customers VALUES
(1, 'Asha Rao', 'Pune', NULL),
(2, 'Ben Okafor', 'Leeds', 1),
(3, 'Chen Wei', 'Pune', 1),
(4, 'Dana Cruz', 'York', 2),
(5, 'Eli Novak', 'Leeds', NULL),
(6, 'Farah Haddad', NULL, 3);
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER REFERENCES customers (customer_id), -- NULL = guest checkout
placed_on DATE NOT NULL,
status VARCHAR(10) NOT NULL
);
INSERT INTO orders VALUES
(101, 1, DATE '2026-03-02', 'shipped'),
(102, 2, DATE '2026-03-05', 'shipped'),
(103, 1, DATE '2026-03-09', 'delivered'),
(104, 3, DATE '2026-03-15', 'pending'),
(105, 4, DATE '2026-03-20', 'cancelled'),
(106, NULL, DATE '2026-03-22', 'shipped');
CREATE TABLE order_items (
order_id INTEGER REFERENCES orders (order_id),
product_id INTEGER REFERENCES products (product_id),
qty INTEGER NOT NULL,
unit_price DECIMAL(8, 2) NOT NULL,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_items VALUES
(101, 1, 1, 249.99), (101, 7, 3, 16.00),
(102, 3, 2, 34.50),
(103, 5, 1, 89.95), (103, 3, 1, 34.50), (103, 7, 2, 15.00),
(104, 2, 1, 489.00),
(105, 6, 1, 54.00),
(106, 7, 1, 16.00);
-- Working days (Monday to Friday) from 2 March to 15 March 2026, inclusive
SELECT COUNT(*) FILTER (WHERE EXTRACT(ISODOW FROM d) < 6) AS working_days,
COUNT(*) AS calendar_days
FROM generate_series(DATE '2026-03-02', DATE '2026-03-15', INTERVAL '1 day') AS d;
-- Each order's dispatch deadline: 3 working days after it was placed
SELECT o.order_id,
o.placed_on,
TO_CHAR(o.placed_on, 'Dy') AS placed_day,
(SELECT CAST(d AS date)
FROM generate_series(o.placed_on + 1, o.placed_on + 10, INTERVAL '1 day') AS d
WHERE EXTRACT(ISODOW FROM d) < 6
ORDER BY d
OFFSET 2 ROWS FETCH FIRST 1 ROW ONLY) AS dispatch_by
FROM orders o
ORDER BY o.order_id;
working_days | calendar_days
--------------+---------------
10 | 14
(1 row)
order_id | placed_on | placed_day | dispatch_by
----------+------------+------------+-------------
101 | 2026-03-02 | Mon | 2026-03-05
102 | 2026-03-05 | Thu | 2026-03-10
103 | 2026-03-09 | Mon | 2026-03-12
104 | 2026-03-15 | Sun | 2026-03-18
105 | 2026-03-20 | Fri | 2026-03-25
106 | 2026-03-22 | Sun | 2026-03-25
(6 rows)
- The first query generates every date from 2 to 15 March and counts those that are Monday to Friday (
ISODOWbelow 6): 10 working days out of 14. - The second finds each order's dispatch deadline, 3 working days after the order date. For each order, a correlated subquery generates the next 10 days, keeps the working days, and takes the third (
OFFSET 2 ... FETCH FIRST 1 ROW ONLY). An order placed on Thursday 5 March must be dispatched by Tuesday 10 March, and the orders placed on Sundays get Wednesday.
Real working-day calculations must also skip public holidays, which differ by country and year. The usual solution is a calendar table with one row per date and columns such as is_working_day (article 41). Then the deadline is "the third row after the order date where is_working_day is true", and the rules live in data rather than in every query.
Overlapping periods
Two periods overlap when each starts before the other ends. For half-open periods, where the end is the first moment not included, such as a booking's departure date:
a.start < b.end AND b.start < a.end
-- Do two periods overlap? Bookings of the same pitch
CREATE TABLE bookings (booking_id INTEGER PRIMARY KEY, pitch TEXT, arrive DATE, depart DATE);
INSERT INTO bookings VALUES
(1, 'A', DATE '2026-07-01', DATE '2026-07-04'),
(2, 'A', DATE '2026-07-03', DATE '2026-07-06'),
(3, 'A', DATE '2026-07-06', DATE '2026-07-08'),
(4, 'B', DATE '2026-07-02', DATE '2026-07-05');
-- Two half-open periods [arrive, depart) overlap when each starts before the other ends
SELECT a.booking_id AS booking, b.booking_id AS clashes_with
FROM bookings a
JOIN bookings b ON b.pitch = a.pitch
AND b.booking_id > a.booking_id
AND a.arrive < b.depart
AND b.arrive < a.depart
ORDER BY booking, clashes_with;
-- The standard OVERLAPS operator does the same test
SELECT (DATE '2026-07-01', DATE '2026-07-04') OVERLAPS (DATE '2026-07-03', DATE '2026-07-06') AS overlap_1_2,
(DATE '2026-07-03', DATE '2026-07-06') OVERLAPS (DATE '2026-07-06', DATE '2026-07-08') AS overlap_2_3;
booking | clashes_with
---------+--------------
1 | 2
(1 row)
overlap_1_2 | overlap_2_3
-------------+-------------
t | f
(1 row)
Bookings 1 and 2 overlap on 3 July. Booking 3 arrives on 6 July, the day booking 2 departs, so they don't overlap: with half-open periods, touching isn't overlapping, and a pitch can be cleaned and re-let on changeover day. b.booking_id > a.booking_id reports each clashing pair once.
The condition is short but easy to get wrong. Common wrong versions check only whether one period's start lies inside the other, which misses a period that contains the other completely. The two-comparison form covers every case.
The standard OVERLAPS operator does the same test, treating periods as half-open: (start1, end1) OVERLAPS (start2, end2). It's supported by PostgreSQL (and, undocumented, by Oracle), not by MySQL, SQL Server or SQLite. PostgreSQL's range types, with the && operator and exclusion constraints, can even stop overlapping bookings from being inserted at all (article 52).
Dates in WHERE: use ranges
CREATE TABLE products (
product_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
category VARCHAR(20) NOT NULL,
brand VARCHAR(20),
price DECIMAL(8, 2) NOT NULL,
stock INTEGER NOT NULL,
weight_g INTEGER
);
INSERT INTO products VALUES
(1, 'Ridge 2 tent', 'tents', 'Alpina', 249.99, 12, 2100),
(2, 'Summit 4 tent', 'tents', 'Alpina', 489.00, 3, 4300),
(3, 'Glow head torch', 'lighting', 'Lumen', 34.50, 40, 90),
(4, 'Basecamp lantern', 'lighting', NULL, 27.00, 15, NULL),
(5, 'Trail 30 backpack', 'packs', 'Kestrel', 89.95, 22, 1150),
(6, 'Day 18 backpack', 'packs', 'Kestrel', 54.00, 0, 640),
(7, 'Merino socks', 'clothing', 'Woolly', 16.00, 75, 80);
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
city VARCHAR(30),
referred_by INTEGER REFERENCES customers (customer_id)
);
INSERT INTO customers VALUES
(1, 'Asha Rao', 'Pune', NULL),
(2, 'Ben Okafor', 'Leeds', 1),
(3, 'Chen Wei', 'Pune', 1),
(4, 'Dana Cruz', 'York', 2),
(5, 'Eli Novak', 'Leeds', NULL),
(6, 'Farah Haddad', NULL, 3);
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER REFERENCES customers (customer_id), -- NULL = guest checkout
placed_on DATE NOT NULL,
status VARCHAR(10) NOT NULL
);
INSERT INTO orders VALUES
(101, 1, DATE '2026-03-02', 'shipped'),
(102, 2, DATE '2026-03-05', 'shipped'),
(103, 1, DATE '2026-03-09', 'delivered'),
(104, 3, DATE '2026-03-15', 'pending'),
(105, 4, DATE '2026-03-20', 'cancelled'),
(106, NULL, DATE '2026-03-22', 'shipped');
CREATE TABLE order_items (
order_id INTEGER REFERENCES orders (order_id),
product_id INTEGER REFERENCES products (product_id),
qty INTEGER NOT NULL,
unit_price DECIMAL(8, 2) NOT NULL,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_items VALUES
(101, 1, 1, 249.99), (101, 7, 3, 16.00),
(102, 3, 2, 34.50),
(103, 5, 1, 89.95), (103, 3, 1, 34.50), (103, 7, 2, 15.00),
(104, 2, 1, 489.00),
(105, 6, 1, 54.00),
(106, 7, 1, 16.00);
-- Date arithmetic on real data: each customer's first and latest order
SELECT c.name,
MIN(o.placed_on) AS first_order,
MAX(o.placed_on) AS latest_order,
MAX(o.placed_on) - MIN(o.placed_on) AS days_between,
DATE '2026-04-01' - MAX(o.placed_on) AS days_since_latest_on_1_april
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.name
ORDER BY c.customer_id;
-- Orders placed in the 7 days up to and including 20 March
SELECT order_id, placed_on
FROM orders
WHERE placed_on > DATE '2026-03-20' - 7
AND placed_on <= DATE '2026-03-20'
ORDER BY placed_on;
name | first_order | latest_order | days_between | days_since_latest_on_1_april
------------+-------------+--------------+--------------+------------------------------
Asha Rao | 2026-03-02 | 2026-03-09 | 7 | 23
Ben Okafor | 2026-03-05 | 2026-03-05 | 0 | 27
Chen Wei | 2026-03-15 | 2026-03-15 | 0 | 17
Dana Cruz | 2026-03-20 | 2026-03-20 | 0 | 12
(4 rows)
order_id | placed_on
----------+------------
104 | 2026-03-15
105 | 2026-03-20
(2 rows)
The first query uses arithmetic on aggregated dates: the days between each customer's first and latest order, and the days from the latest order to 1 April. Asha ordered twice, a week apart.
The second selects the orders in the seven days up to 20 March. Two habits make date filters correct and fast:
- Use half-open ranges for periods:
>= start AND < end_plus_one. "March" isplaced_on >= DATE '2026-03-01' AND placed_on < DATE '2026-04-01'. This works for dates and timestamps alike, never misses times on the last day, and needs no knowledge of how many days the month has.BETWEEN '2026-03-01' AND '2026-03-31'misses everything after midnight on 31 March in a timestamp column. - Do the arithmetic on the constant, not the column.
WHERE placed_on > DATE '2026-03-20' - 7computes one value, and an index onplaced_oncan be used.WHERE placed_on + 7 > DATE '2026-03-20'orWHERE EXTRACT(MONTH FROM placed_on) = 3apply a calculation to every row, which usually prevents index use (article 55).
What's current
- SQLite 3.43 added
timediff()and the'floor'and'ceiling'modifiers, which control what happens when adding months produces a date that doesn't exist. - SQL Server 2022 added
DATE_BUCKETfor fixed-size time buckets andGENERATE_SERIESfor date series. - PostgreSQL 16 added
date_add()anddate_subtract()for adding intervals totimestamptzvalues in a named time zone, which matters when a day isn't 24 hours long across a daylight saving change.
Common questions
What's 31 January plus one month?
28 February (29 in leap years) in PostgreSQL, MySQL, SQL Server and Oracle's ADD_MONTHS. 3 March in SQLite, unless you use the 'floor' modifier.
How do I get the number of days between two dates?
d2 - d1 in PostgreSQL and Oracle, DATEDIFF(d2, d1) in MySQL, DATEDIFF(day, d1, d2) in SQL Server.
Why does SQL Server say there's a year between 31 December and 1 January?
DATEDIFF counts boundaries crossed, not complete units. Use smaller units and divide, or compare the dates directly.
How do I calculate someone's age?
EXTRACT(YEAR FROM AGE(CURRENT_DATE, birth_date)) in PostgreSQL, TIMESTAMPDIFF(YEAR, birth_date, CURDATE()) in MySQL, TRUNC(MONTHS_BETWEEN(SYSDATE, birth_date) / 12) in Oracle.
How do I test whether two periods overlap?
a.start < b.end AND b.start < a.end for half-open periods.
Why shouldn't I use BETWEEN for date ranges?
On timestamp columns, BETWEEN with a date as the end stops at midnight at the start of the last day. A half-open range, >= start AND < next_start, always works.
Summary
date ± integeradds days,date - dategives days, and+ INTERVALadds any unit in PostgreSQL. Other databases useDATEADD,DATE_ADDorADD_MONTHS.- Adding months clamps to the last day of the month, except in SQLite, which overflows. Month arithmetic isn't reversible.
- Subtracting timestamps gives an interval. Use its epoch for hours or days, and
AGEfor calendar-aware years, months and days. - "Months between" can mean boundaries crossed (SQL Server's
DATEDIFF) or complete months (AGE,TIMESTAMPDIFF,MONTHS_BETWEEN). - Count working days with a date series or, better, a calendar table that knows the holidays.
- Periods overlap when each starts before the other ends.
- Filter dates with half-open ranges, and keep calculations on the constant side.
Practice questions
What do DATE '2026-02-28' + INTERVAL '1 month' and DATE '2026-01-30' + INTERVAL '1 month' return in PostgreSQL?
Answer
2026-03-28 00:00:00 and 2026-02-28 00:00:00. 28 March exists, so the day is kept. 30 February doesn't, so the date is clamped to the last day of February.
Write a query that returns the age in whole years, on 1 June 2026, of someone born on 15 June 1990.
Answer
SELECT EXTRACT(YEAR FROM AGE(DATE '2026-06-01', DATE '1990-06-15')) AS age;
- Their 36th birthday is two weeks later. Dividing the 13,135 days by 365 gives 35.99, which only happens to round down correctly here.
What does DATEDIFF(month, '2026-01-31', '2026-02-01') return in SQL Server, and what does TIMESTAMPDIFF(MONTH, '2026-01-31', '2026-02-01') return in MySQL?
Answer
1 in SQL Server, which counts the month boundary crossed. 0 in MySQL, which counts complete months.
Bookings are stored with arrive and depart dates. Write a condition that finds bookings overlapping the period from 4 July (arrival) to 6 July (departure).
Answer
WHERE arrive < DATE '2026-07-06'
AND DATE '2026-07-04' < depart
In the example data, booking 1 (1–4 July) doesn't overlap, because it departs on 4 July, while bookings 2 (3–6 July) and 4 (2–5 July) do.
Rewrite WHERE EXTRACT(YEAR FROM placed_on) = 2026 AND EXTRACT(MONTH FROM placed_on) = 3 so that it can use an index on placed_on.
Answer
WHERE placed_on >= DATE '2026-03-01'
AND placed_on < DATE '2026-04-01'
The comparison is on the column itself, so an index on placed_on can find the range directly.
Previous: Dates and Times in SQL: Types, Current Time, Parts, Formatting and Time Zones
Next: Working With Calendars in SQL: Month Boundaries, Date Series and Missing Dates

More in SQL Course
Quiz: SQL Dialect Differences (PostgreSQL, MySQL, SQL Server, Oracle, SQLite)
Twenty-four questions on how the major SQL databases differ: limiting rows, concatenation, empty strings, identifier case, upserts, identity columns, transactional DDL, error handling, isolation defaults, booleans, set operations, RETURNING, dates and typing.
Quiz: SQL Delicate Details
Twenty-five questions on SQL's subtle corners: NULLs in aggregates, IN and CHECK, sort order of NULLs, rounding, CHAR padding, window frame defaults, identity gaps, LIKE escapes, empty groups, set operations and multi-column updates.
Quiz: SQL Interview Questions
Thirty SQL questions of the kind asked in developer and analyst interviews: WHERE vs HAVING, DELETE vs TRUNCATE, keys, joins, duplicates, Nth-highest values, window functions, ACID, isolation, locking, indexes, views, procedures and performance.
Quiz: SQL Course Final Exam (All 15 Parts)
The final exam for the SQL course: thirty questions across all fifteen parts, from query processing, NULLs, joins and aggregation through windows, data changes, types, design, indexes, security, transactions, procedural SQL and tuning.
Discussion
Sign in to ask a question or share what you learned.