The traditional way is to use convert():

convert(varchar(10), ai.[Due Date], 110)

A more versatile method uses format():

select format(ai.[Due Date], 'dd-MM-yyyy')
Answer from Gordon Linoff on Stack Overflow
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ format-transact-sql
FORMAT (Transact-SQL) - SQL Server | Microsoft Learn
Applies to: SQL Server Azure SQL ... the specified format and optional culture. Use the FORMAT function for locale-aware formatting of date/time and number values as strings....
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ format sql server dates with format function
Format SQL Server Dates with FORMAT Function
October 31, 2025 - Format SQL Date examples using SQL FORMAT Function to format dates, time and numbers in SQL Server with valuable code.
Discussions

sql - Formatting TSQL date to mm-dd-yyyy - Stack Overflow
I have a date in Datetime2 format and it is coming up as yyyy-mm-dd. Is there a way to reformat it so it is mm-dd-yyyy? CASE WHEN CAST(ai.[Due Date] AS DATETIME2)... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Format function doesn't seem to work on date column
I have a column that returns as: DATEADD(DAY, 1, EOMONTH(MyDate, -1)) AS [REPORTING PERIOD] that gets input into a table per Date column of same name [REPORTING PERIOD] when i use the below, it doesn't work: select FORMAT([REPORTING PERIOD],'yyyyMM'), * from MyTable Weirdly, it returns: 202301 ... More on forums.sqlteam.com
๐ŸŒ forums.sqlteam.com
0
February 9, 2023
How do I format a date or convert a date to a specific string?
the default format for the dates in my database is MM/DD/YYYY (01/02/2021) Except it isn't. All date & time data types in SQL Server are stored as binary data, not as strings. They have no "format" - formatting is done by the client application (yes, even SSMS). When you enter a date like 01/02/2021 in an application, the application or SQL Server is making a guess about what you mean based on regional settings and possibly other factors. Unless you're storing your dates as strings. If you're doing that, we gotta have a chat. But like u/IHeartBadCode said, you really need a date table to do this kind of lookup/translation, not code embedded in a query. More on reddit.com
๐ŸŒ r/SQL
6
4
June 23, 2021
sql server - How to get a date in YYYY-MM-DD format from a TSQL datetime field? - Stack Overflow
How do I retrieve a date from SQL Server in YYYY-MM-DD format? I need this to work with SQL Server 2000 and up. Is there a simple way to perform this in SQL Server or would it be easier to convert it More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_dates.asp
Date Functions in SQL Server and MySQL
String Functions: ASCII CHAR_LENGTH ... STR_TO_DATE SUBDATE SUBTIME SYSDATE TIME TIME_FORMAT TIME_TO_SEC TIMEDIFF TIMESTAMP TO_DAYS WEEK WEEKDAY WEEKOFYEAR YEAR YEARWEEK Advanced Functions: BIN BINARY CASE CAST COALESCE CONNECTION_ID CONV CONVERT CURRENT_USER DATABASE IF IFNULL ISNULL LAST_INSERT_ID NULLIF SESSION_USER SYSTEM_USER USER VERSION SQL Server ...
๐ŸŒ
DB Vis
dbvis.com โ€บ thetable โ€บ the-ultimate-guide-to-the-sql-server-date-format
The Ultimate Guide to the SQL Server Date Format
October 23, 2024 - In this guide, you will see standard date formats, explore the date components supported by T-SQL, and understand how to use the FORMAT SQL Server date function.
Top answer
1 of 2
8

The traditional way is to use convert():

convert(varchar(10), ai.[Due Date], 110)

A more versatile method uses format():

select format(ai.[Due Date], 'dd-MM-yyyy')
2 of 2
4

You misunderstand how date values work in a database. There is no human-readable format. When you see DateTime or DateTime2 values formatted as yyyy-mm-dd what you're seeing is something shown by your debugger or query tool for convenience; the actual value used in the database is binary, not human readable, and is intended to be efficient for storage, indexing, and date arithmetic.

If you need to see a value in a specific format, you must convert() or format() it to a type in the varchar family as part of the query. Or, even better, let your application code/reporting tool do this for you, and just return the original value.

I also see indication these dates are potentially stored originally in a varchar, or nvarchar column. If so, it is a major flaw in the schema design. You will get significant performance benefits and save yourself some big headaches down the road if you can start storing these values using a type from the DateTime family in the first place.

With this in mind, and because it's not clear what you're starting from, let's look at five scenarios, in order of preference:

The column already uses a type from the DateTime family, and you can let your application/reporting tool handle the format

Good for you using a real DateTime value in the schema. That's what we expect to see. Even better, suddenly everything gets really simple in your SQL and the entire snippet in the question reduces to just this:

 ai.[Due Date] AS [TD]

The column already uses a type from the DateTime family, but the client system can't format

This is still pretty good. The schema is still okay, and in this case we can still simplify the original code somewhat:

COALESCE(
    CASE WHEN ai.[Due Date] < GETDATE() THEN '[due] ' ELSE '' END 
    + FORMAT(ai.[Due Date], 'MM-dd-yyyy')
, ' ') AS [TD]

The column uses the a type from varchar family, but you can fix it to use DateTime2

I say "fix" here, because now the schema really is broken as is. But that's okay: you can fix it. Do that. Then use the code from a previous scenario.

The column uses the a type from varchar family and you can't fix it, but at least the raw data always uses a semantic 'yyyy-MM-dd` format

Bummer. You're stuck with a broken schema. But we can at least take advantage of the well-formatted data to make things much more efficient by using cast/convert on the get_date() expression to match the column, rather than vice versa as it is now, like this:

WHEN ai.[Due Date] < CONVERT(varchar, GETDATE(), 120)

Now we're doing a string comparison instead of a date comparison, which is generally slower and, well, just wrong. But we can get away with it because of the nice format in the data, and the saving grace is we only need to cast the one get_date() value, rather than every single row we have. Moreover, this way any index on the column would still be valid. The code snippet on the question would be unable to use any index on the [Due Date] column. I know this is a SELECT clause, but this is worth remembering for the general case.

The full solution for this scenario now looks like this:

COALESCE(
    CASE WHEN ai.[Due Date] < CONVERT(varchar, GETDATE(), 120) THEN '[due] ' ELSE '' END
    + FORMAT(CAST(ai.[Due Date]) AS Date), 'MM-dd-yyyy')
, ' ') AS [TD]

Again, only do this if you can't get your raw column data into a DateTime format. That is what you really want here.

The column uses the a type from varchar family, you can't fix it, and the format is not semantic or not consistent

Oh boy. This is where you really don't want to be. If you can do nothing else, at least see if you can start getting consistent and semantic values into your column. At this point, we are stuck with doing extra work on every row we have (possibly more than once) for pretty much every query. Here we go:

COALESCE(
    CASE WHEN CAST(ai.[Due Date] AS DATETIME2)  < GETDATE() THEN '[due] ' ELSE '' END 
    + FORMAT(CAST(ai.[Due Date] AS DATETIME2), 'MM-dd-yyyy')
, ' ') AS [TD]

The code doesn't look much different than other options, but the performance characteristics will be extremely different... potentially multiple orders of magnitude worse.

Remember: because of internationalization and time zone issues, converting between strings and dates is surprisingly slow and expensive. Avoid doing that whenever possible in all your queries.

๐ŸŒ
SQLTeam
forums.sqlteam.com โ€บ transact-sql
Format function doesn't seem to work on date column - Transact-SQL - SQLTeam.com Forums
February 9, 2023 - I have a column that returns as: DATEADD(DAY, 1, EOMONTH(MyDate, -1)) AS [REPORTING PERIOD] that gets input into a table per Date column of same name [REPORTING PERIOD] when i use the below, it doesn't work: select Fโ€ฆ
๐ŸŒ
InfluxData
influxdata.com โ€บ home โ€บ how does date conversion work in sql? | influxdata
How Does Date Conversion Work in SQL? | InfluxData
October 6, 2023 - In this instance, %M, %d, and %Y mean your date will appear with the month name (Januaryโ€ฆDecember), the day of the month in numeric (00โ€ฆ31), and the year in four digits. The MySQL documentation highlights all the available specifiers.
Find elsewhere
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ sql date format examples using convert function
SQL Date Format Examples using SQL CONVERT Function
September 26, 2025 - ... 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.
๐ŸŒ
Experts Exchange
experts-exchange.com โ€บ articles โ€บ 12315 โ€บ SQL-Server-Date-Styles-formats-using-CONVERT.html
SQL Server Date Styles (formats) using CONVERT() | Experts Exchange
October 3, 2013 - 2013-09-21T13:14:15.123 convert(datetime, your_data_here ,126) convert(datetime, your_data_here ,127) -- if there is time zone info CAST and CONVERT (Transact-SQL) SQL 2012? Some new Format sample can be found here
๐ŸŒ
DataSunrise
datasunrise.com โ€บ home โ€บ sql server datetime formats: a comprehensive guide
SQL Server Datetime Formats
July 17, 2025 - Refer to official Microsoft style codes for formatting consistency. Be aware of server locale and language settingsโ€”they can alter input parsing and day-month order. Time zone awareness is critical for global applications. SQL Serverโ€™s datetimeoffset helps ensure consistency when storing UTC and converting to local zones.
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-convert-date-functions-and-formats
SQL Convert Date functions and formats
May 21, 2021 - As highlighted earlier, we might need to format a date in different formats as per our requirements. We can use the SQL CONVERT() function in SQL Server to format DateTime in various formats.
๐ŸŒ
Coffingdw
coffingdw.com โ€บ how-to-format-dates-in-sql-server-over-1800-examples-included
How to Format Dates in SQL Server โ€“ Over 1800 Examples Included โ€“ Software connecting all databases
January 18, 2024 - This blog will brilliantly break down and explain everything about the formatting dates in any way you desire on an Azure Synapse or SQL Server system. I will include over 1800 examples to avoid confusion about formatting dates. Azure Synapse and SQL Server use two ways to format dates: the CONVERT and FORMAT functions to transform raw dates as you want them presented.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ statements โ€บ set-dateformat-transact-sql
SET DATEFORMAT (Transact-SQL) - SQL Server | Microsoft Learn
For an overview of all Transact-SQL date and time data types and functions, see Date and Time Data Types and Functions (Transact-SQL). ... format | @format_var Is the order of the date parts. Valid parameters are mdy, dmy, ymd, ydm, myd, and dym. Can be either Unicode or double-byte character ...
๐ŸŒ
CodingSight
codingsight.com โ€บ home โ€บ sql date format: how to handle it the smart way
SQL Date Format: Easy Ways to Format SQL Dates
September 17, 2025 - In the Philippines, we use two formats: month-day-year and day-month-year. Month-day-year is the general format for numeric dates. But with longer date formats, we interchangeably use day-month-year and month-day-year. At work, I never encountered SQL Server date format settings other than month-day-year.
๐ŸŒ
TablePlus
tableplus.com โ€บ blog โ€บ 2018 โ€บ 09 โ€บ sql-server-date-format-cheatsheet.html
SQL Server Date Format Cheatsheet | TablePlus
September 13, 2018 - In MS SQL Server, you can use the CONVERT() function to converts an expression from one data type to another data type. When it comes to converting datetime value to character, there are so many formatting styles for the output.
๐ŸŒ
Coginiti
coginiti.co โ€บ home โ€บ intermediate โ€บ sql date formats
How to format Dates in SQL - Coginiti
February 1, 2024 - This ensures that wherever you need to format a date, you can use the DateFormat macro, which helps maintain consistency and reduces code duplication. By incorporating this macro, you not only streamline your SQL code but also make it easier for teams to maintain and update date format logic.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ date-and-time-data-types-and-functions-transact-sql
Date and Time Data Types and Functions - SQL Server (Transact-SQL) | Microsoft Learn
February 10, 2026 - Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics SQL database in Microsoft Fabric ยท The sections in this article cover all Transact-SQL date and time data types and functions, including usage and examples.
Top answer
1 of 10
27

Use DATENAME and wrap the logic in a Function, not a Stored Proc

declare @myTime as DateTime

set @myTime = GETDATE()

select @myTime

select DATENAME(day, @myTime) + SUBSTRING(UPPER(DATENAME(month, @myTime)), 0,4)

Returns "14OCT"

Try not to use any Character / String based operations if possible when working with dates. They are numerical (a float) and performance will suffer from those data type conversions.

Dig these handy conversions I have compiled over the years...

/* Common date functions */
--//This contains common date functions for MSSQL server

/*Getting Parts of a DateTime*/
    --//gets the date only, 20x faster than using Convert/Cast to varchar
    --//this has been especially useful for JOINS
    SELECT (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime))

    --//gets the time only (date portion is '1900-01-01' and is considered the "0 time" of dates in MSSQL, even with the datatype min value of 01/01/1753. 
    SELECT (GETDATE() - (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime)))


/*Relative Dates*/
--//These are all functions that will calculate a date relative to the current date and time
    /*Current Day*/
    --//now
    SELECT (GETDATE())

    --//midnight of today
    SELECT (DATEADD(ms,-4,(DATEADD(dd,DATEDIFF(dd,0,GETDATE()) + 1,0))))

    --//Current Hour
    SELECT DATEADD(hh,DATEPART(hh,GETDATE()),CAST(FLOOR(CAST(GETDATE() AS FLOAT)) as DateTime))

    --//Current Half-Hour - if its 9:36, this will show 9:30
    SELECT DATEADD(mi,((DATEDIFF(mi,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)), GETDATE())) / 30) * 30,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)))

    /*Yearly*/
    --//first datetime of the current year
    SELECT (DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))

    --//last datetime of the current year
    SELECT (DATEADD(ms,-4,(DATEADD(yy,DATEDIFF(yy,0,GETDATE()) + 1,0))))

    /*Monthly*/
    --//first datetime of current month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))

    --//last datetime of the current month
    SELECT (DATEADD(ms,-4,DATEADD(mm,1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))))

    --//first datetime of the previous month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()) -1,0))

    --//last datetime of the previous month
    SELECT (DATEADD(ms, -4,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))

    /*Weekly*/
    --//previous monday at 12AM
    SELECT (DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))

    --//previous friday at 11:59:59 PM
    SELECT (DATEADD(ms,-4,DATEADD(dd,5,DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))))

    /*Quarterly*/
    --//first datetime of current quarter
    SELECT (DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0))

    --//last datetime of current quarter
    SELECT (DATEADD(ms,-4,DATEADD(qq,DATEDIFF(qq,0,GETDATE()) + 1,0)))
2 of 10
23

You can use the following command in SQL server to make it:

select FORMAT(getdate(), N'yyyy-MM-ddThh:mm:ss')