Postgres TO_CHAR Date Format Builder
Compose a PostgreSQL TO_CHAR template pattern by clicking tokens or typing it, and see the formatted result instantly for a sample timestamp. The builder understands the real template patterns — YYYY, MM, DD, HH24, MI, SS, MS, US, Month, Day, Dy, Mon, AM, TZ, OF, IW, Q, J, the FM fill-mode modifier, TH/th ordinal suffixes and double-quoted literals — and generates ready-to-run TO_CHAR, TO_TIMESTAMP and TO_DATE statements for your column. Presets cover ISO 8601, US/European dates, RFC 2822, 12-hour clock, year-month buckets and filename-safe stamps. Runs entirely in your browser.
Do more than postgres to_char date format builder — 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
- Pick a preset or type a pattern; click the token buttons (YYYY, FMMonth, HH24, TZ …) to append them and watch the preview update.
- Enter a sample timestamp (YYYY-MM-DD HH:MI:SS.ffffff, interpreted as UTC) and optionally your table, column and an AT TIME ZONE target.
- Copy the generated TO_CHAR query, or the TO_TIMESTAMP / TO_DATE statements to parse strings with the same pattern, and run them in psql or Chat2DB.
Frequently asked questions
What is the difference between MM and MI, and between Month, Mon and MM in TO_CHAR?
MM is the month number (01-12) and MI is minutes (00-59) — mixing them up is the most common TO_CHAR bug. Month is the full English month name blank-padded to 9 characters (use FMMonth to remove the padding), Mon is the three-letter abbreviation, and MONTH/MON/month/mon change the case. The same rule applies to Day/Dy/DAY. Month and day names follow the lc_time setting only when you add the TM modifier; otherwise they are always English.
How do I format a timestamptz in a specific time zone with TO_CHAR?
TO_CHAR formats timestamptz values in the session TimeZone, so first convert: TO_CHAR(created_at AT TIME ZONE 'America/New_York', 'YYYY-MM-DD HH24:MI'). After AT TIME ZONE the value is a plain timestamp, which means TZ and OF patterns print nothing useful — if you need the offset in the output, format the timestamptz directly after SET TIME ZONE 'America/New_York'. This tool adds the AT TIME ZONE expression for you when you fill in a zone name.
Should I store dates as formatted text or format them in the query?
Store dates as date, timestamp or (usually best) timestamptz and format only at output time. Text columns cannot be indexed or compared as dates, break ORDER BY (e.g. '05/08/2026' sorts before '12/01/2025'), and make arithmetic impossible. If you just need to display a value, do it in the application or with TO_CHAR in the outermost SELECT. Chat2DB, a free AI-powered SQL client, shows timestamp columns with proper formatting and lets you test these patterns interactively: download it at https://chat2db.ai/download or use the web version at https://app.chat2db.ai.
