DATE_ADD And DATE_SUBTRACT Across DST Shifts
Step timestamptz across spring-forward and fall-back DST boundaries in an explicit target zone using PostgreSQL 16 date_add and date_subtract.
Code
BEGIN;
-- Keep session in UTC so + INTERVAL uses 24-hour UTC days, while date_add uses the named zone
SET LOCAL TIME ZONE 'UTC';
WITH dst_edges AS (
SELECT
TIMESTAMPTZ '2026-03-08 06:30:00+00' AS spring_ny_0130, -- 01:30 EST before 02:00->03:00 jump
TIMESTAMPTZ '2026-11-01 04:30:00+00' AS fall_ny_0030 -- 00:30 EDT before 02:00->01:00 repeat
)
SELECT
spring_ny_0130 + INTERVAL '1 day' AS utc_plus_24h,
date_add(spring_ny_0130, INTERVAL '1 day', 'America/New_York') AS ny_spring_23h,
date_subtract(
date_add(spring_ny_0130, INTERVAL '1 day', 'America/New_York'),
INTERVAL '1 day',
'America/New_York'
) AS roundtrip_spring,
date_add(fall_ny_0030, INTERVAL '1 day', 'America/New_York') AS ny_fall_25h
FROM dst_edges;
COMMIT;Walkthrough notes — DATE_ADD And DATE_SUBTRACT Across DST Shifts
At its core this is a single SELECT statement against dst_edges.
Mechanically, the statements are built from: a CTE (WITH … AS) that names an intermediate result before the main query.
Using it
Point it at the dst_edges table.
Key statements
SET LOCAL TIME ZONE 'UTC';
Interactive Tools for This Topic
Date Add/Subtract CalculatorAdd or subtract days, weeks, months, or years from a date, clamping month ends such as January 31 plus one month.PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.Date Difference CalculatorCalculate the number of days, weeks, whole months, and years between two ISO dates, computed in UTC.
FAQ
- What objects does the SQL involve?
- `dst_edges` — referenced directly, no join needed.
Report a problem with this exampleOpens a pre-filled issue on GitHub.