SQL Date Format Examples using CONVERT Function

Problem

When querying SQL Server data, dates and times may not always be formatted the way you want. In this article, we look at how to use the SQL CONVERT function to format dates and times in over 100 different formats.

Solution

SQL Server provides a number of date and time formatting options and in this article we look at how to use SQL CONVERT to output different date/time formats such as mm/dd/yy, mm/dd/yyyy, dd-mm-yyyy, etc.

Examples to get SQL Date Format in SQL Server

  • Use SELECT CONVERT and the format option for the date/time format needed
  • To get YYYY-MM-DD use:
    • SELECT CONVERT(varchar, getdate(), 23)
  • To get MM/DD/YY use:
    • SELECT CONVERT(varchar, getdate(), 1)
  • See the table below for all options

SQL Convert Date and Time Format Options

Check out the table below for all of the different format options for Dates and Times.

The date used for all of these examples is “2022-12-30 00:38:54.840” (December 30, 2022). The format is yyyy-mm-dd hh:mm:ss:nnn.

  • yyyy – year
  • mm – month
  • dd – day
  • hh – hour
  • mm – minute
  • ss – second
  • nnn – milisecond

The below queries use the GETDATE() function if you want to return the current date and time.

DATE ONLY FORMATS
Format #QueryFormatSample
1select convert(varchar, getdate(), 1)mm/dd/yy12/30/22
2select convert(varchar, getdate(), 2)yy.mm.dd22.12.30
3select convert(varchar, getdate(), 3)dd/mm/yy30/12/22
4select convert(varchar, getdate(), 4)dd.mm.yy30.12.22
5select convert(varchar, getdate(), 5)dd-mm-yy30-12-22
6select convert(varchar, getdate(), 6)dd Mon yy30 Dec 22
7select convert(varchar, getdate(), 7)Mon dd, yyDec 30, 22
10select convert(varchar, getdate(), 10)mm-dd-yy12-30-22
11select convert(varchar, getdate(), 11)yy/mm/dd22/12/30
12select convert(varchar, getdate(), 12)yymmdd221230
23select convert(varchar, getdate(), 23)yyyy-mm-dd2022-12-30
31select convert(varchar, getdate(), 31)yyyy-dd-mm2022-30-12
32select convert(varchar, getdate(), 32)mm-dd-yyyy12-30-2022
33select convert(varchar, getdate(), 33)mm-yyyy-dd12-2022-30
34select convert(varchar, getdate(), 34)dd-mm-yyyy30-12-2022
35select convert(varchar, getdate(), 35)dd-yyyy-mm30-2022-12
101select convert(varchar, getdate(), 101)mm/dd/yyyy12/30/2022
102select convert(varchar, getdate(), 102)yyyy.mm.dd2022.12.30
103select convert(varchar, getdate(), 103)dd/mm/yyyy30/12/2022
104select convert(varchar, getdate(), 104)dd.mm.yyyy30.12.2022
105select convert(varchar, getdate(), 105)dd-mm-yyyy30-12-2022
106select convert(varchar, getdate(), 106)dd Mon yyyy30 Dec 2022
107select convert(varchar, getdate(), 107)Mon dd, yyyyDec 30, 2022
110select convert(varchar, getdate(), 110)mm-dd-yyyy12-30-2022
111select convert(varchar, getdate(), 111)yyyy/mm/dd2022/12/30
112select convert(varchar, getdate(), 112)yyyymmdd20221230
    
TIME ONLY FORMATS
8select convert(varchar, getdate(), 8)hh:mm:ss00:38:54
14select convert(varchar, getdate(), 14)hh:mm:ss:nnn00:38:54:840
24select convert(varchar, getdate(), 24)hh:mm:ss00:38:54
108select convert(varchar, getdate(), 108)hh:mm:ss00:38:54
114select convert(varchar, getdate(), 114)hh:mm:ss:nnn00:38:54:840
    
DATE & TIME FORMATS
0select convert(varchar, getdate(), 0)Mon dd yyyy hh:mm AM/PMDec 30 2022 12:38AM
9select convert(varchar, getdate(), 9)Mon dd yyyy hh:mm:ss:nnn AM/PMDec 30 2022 12:38:54:840AM
13select convert(varchar, getdate(), 13)dd Mon yyyy hh:mm:ss:nnn AM/PM30 Dec 2022 00:38:54:840AM
20select convert(varchar, getdate(), 20)yyyy-mm-dd hh:mm:ss2022-12-30 00:38:54
21select convert(varchar, getdate(), 21)yyyy-mm-dd hh:mm:ss:nnn2022-12-30 00:38:54.840
22select convert(varchar, getdate(), 22)mm/dd/yy hh:mm:ss AM/PM12/30/22 12:38:54 AM
25select convert(varchar, getdate(), 25)yyyy-mm-dd hh:mm:ss:nnn2022-12-30 00:38:54.840
26select convert(varchar, getdate(), 26)yyyy-dd-mm hh:mm:ss:nnn2022-30-12 00:38:54.840
27select convert(varchar, getdate(), 27)mm-dd-yyyy hh:mm:ss:nnn12-30-2022 00:38:54.840
28select convert(varchar, getdate(), 28)mm-yyyy-dd hh:mm:ss:nnn12-2022-30 00:38:54.840
29select convert(varchar, getdate(), 29)dd-mm-yyyy hh:mm:ss:nnn30-12-2022 00:38:54.840
30select convert(varchar, getdate(), 30)dd-yyyy-mm hh:mm:ss:nnn30-2022-12 00:38:54.840
100select convert(varchar, getdate(), 100)Mon dd yyyy hh:mm AM/PMDec 30 2022 12:38AM
109select convert(varchar, getdate(), 109)Mon dd yyyy hh:mm:ss:nnn AM/PMDec 30 2022 12:38:54:840AM
113select convert(varchar, getdate(), 113)dd Mon yyyy hh:mm:ss:nnn30 Dec 2022 00:38:54:840
120select convert(varchar, getdate(), 120)yyyy-mm-dd hh:mm:ss2022-12-30 00:38:54
121select convert(varchar, getdate(), 121)yyyy-mm-dd hh:mm:ss:nnn2022-12-30 00:38:54.840
126select convert(varchar, getdate(), 126)yyyy-mm-dd T hh:mm:ss:nnn2022-12-30T00:38:54.840
127select convert(varchar, getdate(), 127)yyyy-mm-dd T hh:mm:ss:nnn2022-12-30T00:38:54.840
    
ISLAMIC CALENDAR DATES
130select convert(nvarchar, getdate(), 130)dd mmm yyyy hh:mi:ss:nnn AM/PMdate output
131select convert(nvarchar, getdate(), 131)dd mmm yyyy hh:mi:ss:nnn AM/PM7/06/1444 12:38:54:840AM

Format Date or Time without Dividing Characters

Format the date or time without dividing characters and concatenate the date and time string:

Sample statementFormatOutput
select replace(convert(varchar, getdate(),101),’/’,”)mmddyyyy12302022
select replace(convert(varchar, getdate(),101),’/’,”) + replace(convert(varchar,
getdate(),108),’:’,”)
mmddyyyyhhmmss12302022004426

Another option is to use the SQL FORMAT function as follows:

SELECT FORMAT(GETDATE(), 'yyyyMMddHHmmss')

Get List of all Valid Date and Time Formats

Get a list of all valid date and time formats, using the code below. Change the @date to GETDATE() or any other date you want to use.  This will output just the valid formats.

DECLARE @counter INT = 0
DECLARE @date DATETIME = '2022-12-30 00:38:54.840'
CREATE TABLE #dateFormats (dateFormatOption int, dateOutput nvarchar(40))
WHILE (@counter <= 150 )
BEGIN
   BEGIN TRY
      INSERT INTO #dateFormats
      SELECT CONVERT(nvarchar, @counter), CONVERT(nvarchar,@date, @counter) 
      SET @counter = @counter + 1
   END TRY
   BEGIN CATCH;
      SET @counter = @counter + 1
      IF @counter >= 150
      BEGIN
         BREAK
      END
   END CATCH
END
SELECT * FROM #dateFormats

Table of Date Data Types in SQL Server

Data TypeDescriptionRangeStorageExample
dateA date without a time0001-Jan-01 –
9999-Dec-31
3 bytes2023-Dec-17
Time (factional seconds)A time on a 24-hour clock without a date.
There can be between 0 and 7 decimal places to support fractional seconds.
The default is 7.
00:00:00.0000000 –
23:59:59.9999999
Differs based on the scale of the fractional
seconds.3 bytes for 0-24 bytes for 3-45 bytes for 5-7
time(0)
16:23:45time(4)
16:23:45.5468time(7)
16:23:45.5468375
datetimeA date and time together in one column.
The precision of the time is 1/300th
of a second.
1753-Jan-01 00:00:00.000 –
9999-Dec-21 23:59:59.997
8 bytes2023-Dec-17 17:23:45.547
smalldatetimeA date and time together in one column.
The precision of the time 1 minute. There are no seconds and no fractions
of a second.
1900-Jan-01 00:00 –
2079-Jun-06 23:59
4 bytes2023-Dec-17 16:23
datetime2 (factional seconds)A date and time together in one column.
There can be between 0 and 7 decimal places to support fractional seconds
of the time. The default is 7.
0001-Jan-01 00:00:00.0000000 –
9999-Dec-31 23:59:59.9999999
Differs based on the scale of the fractional
seconds.6 bytes for 0-27 bytes for 3-48 bytes for 5-7
datetime2(0)
2023-Dec-17 16:23:45datetime2(4)
2023-Dec-17 16:23:45.5468datetime2(7)
2023-Dec-17 16:23:45.5468375
Datetimeoffset(factional seconds)This is exactly the same as a datetime2 except
that it also includes a time zone offset value. This data type requires
at least SQL Server 2016
0001-Jan-01 00:00:00.0000000 –
9999-Dec-31 23:59:59.9999999With a time zone between UTC-14:00 and UTC+14:00
Differs based on the scale of the fractional
seconds.8 bytes for 0-29 bytes for 3-410 bytes for 5-7
datetimeoffset(0)
2023-Dec-17 16:23:45+08:00datetimeoffset(4)
2023-Dec-17 16:23:45.5468+08:00datetimeoffset(7)
2023-Dec-17 16:23:45.5468375+08:00

Here are links to date data type articles:

SQL Date Format dd/mm/yyyy with SQL CONVERT

First is an example for the SQL date format as dd/mm/yyyy. This is two-digit day, two-digit month and four-digit year output.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--dd/mm/yyyy with 4 DIGIT YEAR
SELECT CONVERT(VARCHAR(10), @Datetime, 103) CurrentDateFormattedAsText;
 
--dd/mm/yy with 2 DIGIT YEAR
SELECT CONVERT(VARCHAR(8), @Datetime,   3) CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 25, 2013. 
--SELECT a datetime column as a string formatted dd/mm/yyyy (4 digit year)
SELECT TOP 3 CONVERT(CHAR(10), ExpectedDeliveryDate, 103) ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted dd/mm/yy (2 digit year)
SELECT TOP 3 CONVERT(CHAR(8), ExpectedDeliveryDate, 3) ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

Once the query runs, review SQL CONVERT output as shown below.

SQL Format dd/mm/yyyy

SQL Date Format mm/dd/yyyy with SQL CONVERT

Second, is SQL CONVERT example for the two-digit month, two-digit day and four-digit year.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--mm/dd/yyyy with 4 DIGIT YEAR
SELECT CONVERT(VARCHAR(10), @Datetime, 101) CurrentDateFormattedAsText;
 
--mm/dd/yy with 2 DIGIT YEAR
SELECT CONVERT(VARCHAR(8), @Datetime,   1) CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013.
--SELECT a datetime column as a string formatted mm/dd/yyyy (4 digit year)
SELECT TOP 3 CONVERT(CHAR(10), ExpectedDeliveryDate, 101) ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted mm/dd/yy (2 digit year)
SELECT TOP 3 CONVERT(CHAR(8), ExpectedDeliveryDate, 1) ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

Next, review the output from the T-SQL code above.

Date Format mm/dd/yyyy

SQL Date Format yyyy mm dd with SQL CONVERT

Third is an example of SQL CONVERT formatting the date as a four-digit year, two-digit month and two-digit day without any slashes.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--yyyy mm dd with 4 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(10), @Datetime, 102), '.', ' ') CurrentDateFormattedAsText;
 
--yy mm dd  with 2 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(8), @Datetime,   2), '.', ' ') CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013.
--SELECT a datetime column as a string formatted yyyy mm dd (4 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(10), ExpectedDeliveryDate, 102), '.', ' ') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted yy mm dd (2 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(8), ExpectedDeliveryDate, 2), '.', ' ') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

Note the SQL CONVERT logic output below without any slashes.

T-SQL results for yyyy mm dd with SQL CONVERT

SQL Date Format yyyymmdd with SQL CONVERT

Fourth, is SQL CONVERT example without slashes or spaces separating the year, month and day.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--yyyymmdd with 4 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(10), @Datetime, 112), '.', ' ') CurrentDateFormattedAsText;
 
--yymmdd  with 2 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(8), @Datetime,  12), '.', ' ') CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013.
--SELECT a datetime column as a string formatted yyyymmdd (4 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(10), ExpectedDeliveryDate, 112), '.', ' ') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted yymmdd (2 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(8), ExpectedDeliveryDate, 12), '.', ' ') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

The output from the logic is shown below:

T-SQL results for SQL Date Format yyyymmdd

SQL Date format ddmmyyyy with SQL CONVERT

Fifth, is a code example that changes the order of the date and excludes slashes or spaces in the date format.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--ddmmyyyy with 4 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(10), @Datetime, 104), '.', '') CurrentDateFormattedAsText;
 
--ddmmyy  with 2 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(8), @Datetime,   4), '.', '') CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013.
--SELECT a datetime column as a string formatted ddmmyyyy (4 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(10), ExpectedDeliveryDate, 104), '.', '') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted ddmmyy (2 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(8), ExpectedDeliveryDate,  4), '.', '') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

The screen shot below includes multiple sets of output for dates without slashes or spaces.

T-SQL results for SQL Date format ddmmyyyy

SQL Date Format yyyy-mm-dd with SQL CONVERT

SQL CONVERT code for a four-digit year, two-digit month and two-digit date.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--yyyy-mm-dd with 4 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(10), @Datetime, 111), '/', '-') CurrentDateFormattedAsText;
 
--yy-mm-dd  with 2 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(8), @Datetime,   11), '/', '-') CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013.
--SELECT a datetime column as a string formatted yyyy-mm-dd (4 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(10), ExpectedDeliveryDate, 111), '/', '-') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted yy-mm-dd (2 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(8), ExpectedDeliveryDate, 11), '/', '-') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

Consider this output to use as a prefix for backup files to easily sort the file name by date.

T-SQL results for sql convert date yyyy-mm-dd

SQL Date Format mm-dd-yyyy with SQL CONVERT

Seventh is SQL CONVERT example where the slashes are replaced by dashes. This can be accomplished using CONVERT option 110.

-- The date used for this example was November 12, 2023.
DECLARE @Datetime DATETIME;
SET @Datetime = GETDATE();
 
--mm/dd/yyyy with 4 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(10), @Datetime, 110), '/', '-') CurrentDateFormattedAsText;
 
--mm/dd/yy  with 2 DIGIT YEAR
SELECT REPLACE(CONVERT(VARCHAR(8), @Datetime,   10), '/', '-') CurrentDateFormattedAsText;

-- pull data from a database table
-- The date used for this example was January 15, 2013. 
--SELECT a datetime column as a string formatted mm/dd/yyyy (4 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(10), ExpectedDeliveryDate, 110), '/', '-') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;
 
--SELECT a datetime column as a string formatted mm/dd/yy (2 digit year)
SELECT TOP 3 REPLACE(CONVERT(CHAR(8), ExpectedDeliveryDate, 10), '/', '-') ExpectedDeliveryDateFormattedAsText
FROM Purchasing.PurchaseOrders
WHERE OrderDate < @Datetime;

Here is the output.

T-SQL results for sql convert date mm/dd/yyyy

Continue your learning on Microsoft SQL Server dates with these tips and tutorials which could be valuable to beginners and experienced Developers alike:

Key Takeaways

  • The article explains how to use the SQL CONVERT function to achieve various sql date format styles.
  • It covers common formats like mm/dd/yy and dd-mm-yyyy with practical SQL queries as examples.
  • Users can access a table listing all date and time format options along with SQL syntax for each format.
  • Additionally, the article includes a table of all the date format options.
  • For further learning, it provides recommended resources including tutorials on SQL Server date functions.

Next Steps

  • The formats listed above are not inclusive of all formats provided. Experiment with various dates and the different format numbers to see what others are available.
  • Date formats can be used for all date/time functions and data served to client applications. Experiment with these data format conversions.
  • Check out the SQL Server FORMAT Function to Format Dates.

Last updated by Sebastiao Pereira and Greg Robidoux on 2025-09-26.

23 Comments

  1. Could you please provide the official source for the Date & Time formats like “select convert(varchar, getdate(), 29)”.

    • Just run the command and you can see the output. Also, you could look at the CONVERT function on the Microsoft site.

  2. Please use dates and time values that cannot be misinterpreted, i.e. 2032-12-31 since there is no day value 32 and no month value 31. You can easily see the difference in the formatted string. With 23-11-12 its not easy to see if the format is YY-MM-DD or DD-MM-YY or DD-YY-MM etc. but with 32-12-31 you see clearly that it must be YY-MM-DD, there is no doubt.

    With time values it is more difficult, but use at least a hour value that differs in 24-hour and 12-hour represantation, eg. 20. So you can better see the difference.

  3. Great article – I use it all the time being a Data Warehouse professional (lot to do with dates, left and right :)

    • Hi Raj,

      I’m trying to grow as a professional. I was a regular dude that used excel to manipulate data for reporting purposes – more so operational – that has been thrust into the I.T. department now building SSIS packages and so on. Needed some advice, if possible?

  4. Thank you for the article, I was trying to fix the Date format issue while troubleshooting a website and it helped a lot.
    Keep up the good work.

  5. SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.’
    I found this type of error, I can i solve this

  6. Thank you for the article, I was trying to fix the Date format issue while troubleshooting a website and it helped a lot.
    Keep up the good work.

  7. Hi Osman,

    You could just do UPDATE statements to convert your text values to the standard time values you mentioned. Another option is to use a CASE statement to make the change if you don’t want to change the actual data.

    https://www.mssqltips.com/sqlservertip/6031/sql-server-case-expression-overview/

    -Greg

  8. Hi,

    Please help me with this..

    I got a really messy data that I am trying to clean. There is a column there that has time. Most of the time values are entered in this format 18h00, which is fine. But there are rows that have “morning” or “afternoon” or “after dark” instead of actual time.

    My question is: how do I convert these strings like “afternoon” which I know could be like “13h00” or something to a time value instead of having it as a string.

  9. hi i convert ‘2015-04-14 00:30:00.000’ to ‘2015-04-14 24:30:00.000’ in sql

    (my parametr type as datetime)

    please help me

  10. Hi Krishna,

    try this.

    declare @d int = 44542 — Dec 14, 2021
    select CONVERT(varchar(25),cast(@d as datetime),105)

    -Greg

  11. Hi,

    I want to convert a Text Field which is saving the Data in String into a Date field. The value stored is in the below format.

    Value Stored = 66028
    Actual Value (or) Desired Output = 10-11-2021 (dd-mm-yyyy)

    Thanks,
    Krishna

  12. Hi Amol,

    you could create another table with the mapping and then join to that table based on the day of the month to return your A, B, C, etc. values.

    -Greg

  13. Hello,
    i am beginner in sql
    i have one task of conversion of date like.
    if day of month is 01 then conversion would like A, like for 02 it would be B( 01= A,02=B,…….27=AA,28=AB…)

    could we do like code this sql please suggest solution if it could be done.

    Thanks

  14. Example #3 st the top of the article is wrong. You indicate that YYYY will be returned by format value 1. But this format only returns YY, as you indicate in the chart immediately below. 101 returns the year with century.

Leave a Reply

Your email address will not be published. Required fields are marked *