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
Check these values
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.
Your result
How it was worked out
How to use the converter
- Choose a task. A date as text in a format, in each engine is the first choice.
- 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. - Type the date and time to try and the name of your column.
- Choose Convert. The table gives the expression for each engine and the text it returns.
The same element in each engine
| 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,
MMis the month andMIthe minutes.HHis the 12-hour clock: useHH24for 00 to 23. The tool stopshh:mmand says so. - In SQL Server FORMAT,
MMis the month andmmthe 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.
FMturns that off: in PostgreSQL it applies to the next element, in Oracle it switches on and off, so the Oracle form hasFMtwice. - 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
- For Unix time (epoch seconds or milliseconds) to an SQL date, use Unix Timestamp to SQL Date.
- To change other column types between engines, use the SQL Data Type Converter.
- For one date in many written forms (ISO 8601, Excel serial, Julian day), use the Date Format Converter.
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.