PostgreSQL Interval Converter (ISO 8601, IntervalStyle, Epoch)
Paste one or more durations, such as an ISO 8601 value from an API (PT1H30M, P1Y2M10DT2H30M), a Postgres interval string (1 day 02:03:04.5, 1.5 months, 2 weeks ago) or a number of seconds, and see how PostgreSQL parses and prints it. The converter shows the value under every IntervalStyle setting (postgres, postgres_verbose, sql_standard, iso_8601), the months/days/microseconds it is stored as, the justify_hours(), justify_days() and justify_interval() results, extract(epoch from ...) and an equivalent make_interval() call. Parsing follows PostgreSQL's own interval input rules, including fractional units and the exact error messages, and runs entirely in your browser.
Input is parsed as PostgreSQL does with the default IntervalStyle (postgres). With IntervalStyle = sql_standard, a leading minus sign in a value like -1 2:03:04 applies to every field instead of only the first one.
Do more than postgresql interval converter (iso 8601, intervalstyle, epoch) — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Paste one duration per line: ISO 8601 (P1DT2H), Postgres style (1 day 2 hours, -1 day +02:00:00), SQL standard (1-2 3 4:05:06) or plain seconds.
- Click Convert to see each value in all four IntervalStyle formats plus its internal months, days and microseconds.
- Use the justify_*(), extract(epoch) and make_interval() results to write the query or to store the duration in another system.
Frequently asked questions
How do I convert an ISO 8601 duration to a Postgres interval?
Cast it directly: SELECT 'PT1H30M'::interval returns 01:30:00. PostgreSQL accepts the ISO 8601 designator format on input regardless of the IntervalStyle setting. To get ISO 8601 back out, run SET IntervalStyle = 'iso_8601' for the session, or set it per role or database.
Why does extract(epoch from interval '1 month') return 2592000?
An interval stores months, days and microseconds separately because months and days have no fixed length. When you ask for a total number of seconds, PostgreSQL counts a month as 30 days and a year as 365.25 days, so one month is 2,592,000 seconds. For exact elapsed time, subtract two timestamps instead.
Can I check interval queries against a real database?
Yes. Chat2DB connects to PostgreSQL, runs your interval and date queries, and its AI assistant can write date arithmetic for you. Download it from chat2db.ai/download or use the web version at app.chat2db.ai.
