Toolvito

Works on this device

SQL Date Format Converter

Write a date format once and get it for every engine: TO_CHAR for PostgreSQL and Oracle, DATE_FORMAT for MySQL, FORMAT and CONVERT style numbers for SQL Server, and strftime for SQLite. See the text each one gives for your date, read a text such as 15/03/2026 as a date, and change datetime to date and back. No SQL is run.

Enter your values

Type a format in the notation of one engine. You get the same format in every engine, the expression for your column, and the text it gives for the date you typed.

Your values

The tool reads the format in this notation and writes it again for every engine.

In the TO_CHAR notation: YYYY year, MM month, DD day, HH24 hour, MI minutes, SS seconds, MS milliseconds, Mon short month name. Literal letters go in "double quotes".

The column (or a variable such as @d) that holds the date. It is written into the SQL as typed.

More options

The part of the second after the time, 0 to 999999. 250000 is a quarter of a second.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Convert.

How to use the converter

  1. Choose a task. A date as text in a format, in each engine is the first choice.
  2. Say how your format is written (TO_CHAR, MySQL, SQL Server FORMAT or SQLite), and type it, such as DD/MM/YYYY. Or pick a common format from the list.
  3. Type the date and time to try and the name of your column.
  4. Choose Convert. The table gives the expression for each engine and the text it returns.

The same element in each engine

Format elements
Element TO_CHAR (PostgreSQL, Oracle) MySQL DATE_FORMAT SQL Server FORMAT SQLite strftime
Year, 4 digits YYYY %Y yyyy %Y
Year, 2 digits YY %y yy substr of %Y
Month 01 to 12 MM %m MM %m
Month name, short Mon %b MMM a CASE on %m
Month name FMMonth %M MMMM a CASE on %m
Day 01 to 31 DD %d dd %d
Day name FMDay %W dddd a CASE on %w
Hour 00 to 23 HH24 %H HH %H
Hour 01 to 12 HH12 %h hh worked out from %H
Minutes MI %i mm %M
Seconds SS %s ss %S
Milliseconds MS (Oracle FF3) LEFT of %f fff part of %f
Microseconds US (Oracle FF6) %f ffffff not kept
AM or PM AM %p tt a CASE on %H

Worked examples

Format: DD/MM/YYYY for 5 March 2026 gives 05/03/2026. In MySQL it is DATE_FORMAT(order_date, '%d/%m/%Y'), in SQL Server CONVERT(varchar(10), order_date, 103), and in SQLite strftime('%d/%m/%Y', order_date).

Read a text: 15/03/2026 with DD/MM/YYYY is the date 2026-03-15, a Sunday. PostgreSQL and Oracle read it with TO_DATE('15/03/2026', 'DD/MM/YYYY'), MySQL with STR_TO_DATE('15/03/2026', '%d/%m/%Y') and SQL Server with CONVERT(date, '15/03/2026', 103).

Styles: for 2026-03-05 14:30:05.123, style 112 gives 20260305, style 103 gives 05/03/2026, style 120 gives 2026-03-05 14:30:05, and style 100 gives Mar 5 2026 2:30PM with an extra space before the day 5 and before the hour 2, which are padded to two places.

Types: the date of a datetime is CAST(x AS date) in PostgreSQL and SQL Server, DATE(x) in MySQL, TRUNC(x) in Oracle and date(x) in SQLite.

Things that often go wrong

  • In TO_CHAR, MM is the month and MI the minutes. HH is the 12-hour clock: use HH24 for 00 to 23. The tool stops hh:mm and says so.
  • In SQL Server FORMAT, MM is the month and mm the minutes, and / and : follow the culture. The expressions give the culture en-US.
  • TO_CHAR pads month and day names with spaces to the longest name. FM turns that off: in PostgreSQL it applies to the next element, in Oracle it switches on and off, so the Oracle form has FM twice.
  • A two-digit year is read differently by each engine, so reading a text needs a four-digit year.

Other tools for the same subject

Limits you should know

  • Names of months and days are English here. Engines follow their language settings (NLS_DATE_LANGUAGE in Oracle, lc_time_names in MySQL, the culture in SQL Server FORMAT).
  • Week numbers, the day of the year, time zones and era marks are not converted.
  • No SQL is run. Test the expression in your own database version before you use it on real data.

Related tools