SELECT CONVERT(char(10), GetDate(),126)

Limiting the size of the varchar chops of the hour portion that you don't want.

Answer from Darrel Miller 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 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
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
0
February 9, 2023
Converting date format in sqlserver
The date is a binary field (stores binary value regardless of formatting). When SQL store date, it is not using any format at all. So, you do not store date in SQL by any format - only displays based on the local set of your server. More on learn.microsoft.com
🌐 learn.microsoft.com
4
0
🌐
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 ...
🌐
Sqldates
sqldates.com
SQL Date Formatting Tool
This utility is meant to help you parse and format dates when using Microsoft 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.
🌐
W3Schools
w3schools.com › sql › sql_datatypes.asp
SQL Data Types for MySQL, SQL Server, and MS Access
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 ...
Find elsewhere
🌐
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
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.

🌐
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.
🌐
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…
🌐
Simplilearn
simplilearn.com › home › resources › software development › sql date format to convert and format dates easily
SQL Date Format Guide: Syntax & Examples
July 31, 2025 - SQL date variables typically use the yyyy-MM-dd format. For example, DATE, DATETIME, or SMALLDATETIME are the defaults in this format.
🌐
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.
🌐
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.
🌐
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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1425205 › converting-date-format-in-sqlserver
Converting date format in sqlserver - Microsoft Q&A
The date is a binary field (stores binary value regardless of formatting). When SQL store date, it is not using any format at all. So, you do not store date in SQL by any format - only displays based on the local set of your server.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › data-types › date-transact-sql
date (Transact-SQL) - SQL Server | Microsoft Learn
This format is the same as the ISO 8601 definition for DATE. ... For Informatica, the range is limited to 1582-10-15 (October 15, 1582 CE) to 9999-12-31 (December 31, 9999 CE). Some down-level clients don't support the time, date, datetime2, and datetimeoffset data types. The following table shows the type mapping between an up-level instance of SQL Server and down-level clients.
🌐
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.