The date datatype doesn't have a concept of a format. It's just a moment in time perhaps with a timezone attached but without any particular fixed representation. When you format it, it becomes a varchar. If you cast the varchar back to a date, it loses the format. This will be pretty much the same in any programming language that has a native date datatype (or date/datetime objects). It's not specific to SQL.

If you want a particular string representation of a date, then you want a varchar, so don't try to cast it back to a date.

This seems to be what's called an XY problem. What is wrong with CONVERT(varchar(12), GETDATE(), 103)? Yes, it's a varchar, but what's why are you unsatisfied with it being a varchar?

Answer from tobyink on Stack Overflow
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 71651161 โ€บ convert-varchar-date-format-from-yyyy-mm-dd-to-yyyymmdd-in-sql
sql server - Convert Varchar date format from yyyy-MM-dd to yyyyMMdd in SQL - Stack Overflow
Hi I am trying to convert Varchar date format from yyyy-MM-dd to yyyyMMdd in SQL.I tried the below approaches but nothing is working. Declare @doj VARCHAR(10) Set @doj='2022-01-01' Select convert (
Discussions

Convert Date mm/dd/yyyy in to yyyymmdd - SQL Server Forums
Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers. More on sqlteam.net
๐ŸŒ sqlteam.net
Convert getdate() to dd/mm/yyyy in SQL Server - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
convert date ( yyyy-mm-dd) to (mm-dd-yyyy) - SQL Server Forums
Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers. More on sqlteam.com
๐ŸŒ sqlteam.com
February 11, 2010
How to change date format from YYMMDD to DD-MM-YYYY
Hi Team, Can any one help to convert date format YYMMDD to DD-MM-YYYY in a sql script. In data I have a date like 220504 which I want to convert into 04-05-2022. I have tried below given way but i am getting error. cโ€ฆ More on forums.sqlteam.com
๐ŸŒ forums.sqlteam.com
0
July 10, 2023
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_sqlserver_convert.asp
SQL Server CONVERT() Function
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ sql date format examples using convert function
SQL Date Format Examples using SQL CONVERT Function
September 26, 2025 - --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;
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ cast-and-convert-transact-sql
CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn
When you convert between datetimeoffset and the character types char, nchar, nvarchar, and varchar, the converted time zone offset part should always have double digits for both HH and MM.
๐ŸŒ
Sqlteam
sqlteam.net โ€บ forums โ€บ topic.asp
Convert Date mm/dd/yyyy in to yyyymmdd - SQL Server Forums
Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers.
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-convert-date-functions-and-formats
SQL Convert Date functions and formats
May 21, 2021 - We can combine the SQL DATEADD and CONVERT functions to get output in desired DateTime formats. Suppose, in the previous example; we want a date format in of MMM DD, YYYY.
Find elsewhere
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-server-functions-for-converting-string-to-date
SQL Server functions for converting a String to a Date
May 21, 2021 - In SQL Server, converting string to date implicitly depends on the string date format and the default language settings (regional settings); If the date stored within a string is in ISO formats: yyyyMMdd or yyyy-MM-ddTHH:mm:ss(.mmm), it can be converted regardless of the regional settings, else the date must have a supported format or it will throw an exception, as an example while working under the regional settings โ€œEN-USโ€, if we try to convert a string with dd/MM/yyyy format it will fail since it tries to convert it as MM/dd/yyyy format which is supported.
๐ŸŒ
SQL Team
sqlteam.com โ€บ forums โ€บ topic.asp
convert date ( yyyy-mm-dd) to (mm-dd-yyyy) - SQL Server Forums
February 11, 2010 - Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
๐ŸŒ
SQLTeam
forums.sqlteam.com โ€บ other sql server topics
How to change date format from YYMMDD to DD-MM-YYYY - Other SQL Server Topics - SQLTeam.com Forums
July 10, 2023 - Hi Team, Can any one help to convert date format YYMMDD to DD-MM-YYYY in a sql script. In data I have a date like 220504 which I want to convert into 04-05-2022. I have tried below given way but i am getting error. cโ€ฆ
๐ŸŒ
Google
discuss.google.dev โ€บ google cloud โ€บ database
How to Change Date Format to dd/mm/yyyy (Example: 28/10/2022) - Database - Google Developer forums
October 19, 2022 - Hello, I want to ask. Iโ€™m a SQL Server Express 2017 user. I want to ask, how do I change the date format in the system (not in SQL) to dd/mm/yyyy (Example: 28/10/2022)? If using the Windows Operating System, this can be โ€ฆ
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ format sql server dates with format function
Format SQL Server Dates with FORMAT Function
October 31, 2025 - If we want to change to the yyyy MM dd FORMAT using the format function, the following example can help you to do it.
Top answer
1 of 3
5

I understand your problem to be how to successfully convert the string into a DATE value. An undelimited string of integers is assumed to be Year-Month-Day order. (And, of course, I agree with the comments that dates should be stored in DATE data types in the database.)

Reviewing the MSDN CONVERT documentation does not show a built-in conversion for your string, but it is easy to work around.

http://msdn.microsoft.com/en-us/library/ms187928.aspx -- CAST and CONVERT

I changed the month to 8 to make it easier to double check. Using the CONVERT style option 3, you can do the following:

DECLARE @String VARCHAR(10);
DECLARE @DateValue DATE;
SET @String = '250809'; 

-- Convert your undelimited string DDMMYY into a DATE
-- First: Add / between the string parts.
SET @STRING = SUBSTRING(@String,1,2)+'/'+
     SUBSTRING(@String,3,2)+'/'+SUBSTRING(@String,5,2);
-- Second: Convert using STYLE 3 to get DD/MM/YY interpretation
SELECT @DateValue = CONVERT(Date, @String, 3);

-- Using the DATE 
-- Select the value in default Year-Month-Day
SELECT @DateValue AS DefaultFormat;    
-- Select the value formatted as dd/mm/yy
SELECT CONVERT(VARCHAR(20),@DateValue,3) AS [DD/MM/YY];

The results of the last two selects are:

DefaultFormat
-------------
2009-08-25

DD/MM/YY
--------
25/08/09

To get your DATE formatted in the way you want it, you have to insert the '/' delimiters then use the STYLE 3 in converting from the string to the DATE. (I am sure that there are other workarounds and conversion styles that would work as well.)

Likewise when displaying the DATE as you desire, you need to use STYLE 3

2 of 3
3

Another approach is to cast it directly to a date in SQL Server 2008 or above, then store it that way as @ypercube commented above. Assuming 2000 <= all expected years <= 2099:

DECLARE @d CHAR(6) = '250909';
SELECT DATEFROMPARTS('20'+RIGHT(@d,2),SUBSTRING(@d,3,2),LEFT(@d,2));

You may need to do things a little differently if you could have 250999 etc, then you would need some way to indicate whether that's 1999 or 2099, for example. This also doesn't handle validation (like the other answer, it will choke on values like 252525).

When you want to display the date, then format it at the display/presentation layer, but store it correctly in the database. I still question whether it is actually useful to display as ambiguous formats like 25/09/2009 - for that date specifically it's clearly September 25th, but are you sure your entire audience will always get 07/08/2009 correctly? While I'm in the USA that's July 8th, but last week I was in Canada, and I would expect that to be August 7th. Output formats like 2009-07-08 are much clearer and less prone to misinterpretation; even better would be July 8th, 2009 - but then that opens the door to folks using a different language. All that said, these formats can be completely controlled by the client application (C# has very powerful formatting functions), and shouldn't dictate how you actually store the data in the database. They should be stored as dates because you get automatic validation, all of the date/time functionality, etc. Stop storing dates as strings (and maybe even try to get the CSV to contain more reliable literal formats, like YYYYMMDD). Some useful reading perhaps:

  • https://sqlblog.org/2009/10/12/bad-habits-to-kick-choosing-the-wrong-data-type

  • https://sqlblog.org/2009/10/16/bad-habits-to-kick-mis-handling-date-range-queries

๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ sql-date-formatting-getting-your-dates-into-yyyymmdd โ€บ 0851b92d961bf96ea61a10b9da245dcb
SQL Date Formatting: Getting Your Dates Into YYYY-MM-DD - Oreate AI Blog
4 weeks ago - Learn how to convert various date formats into the standard YYYY-MM-DD format for SQL queries using functions like CONVERT, DATE_FORMAT, and TO_CHAR across different database systems.
๐ŸŒ
Quest Blog
blog.quest.com โ€บ home โ€บ various ways to use the sql convert date function
Various ways to use the SQL CONVERT date function
April 26, 2024 - DECLARE @Inputdate datetime = '2019-12-31 14:43:35.863'; Select CONVERT(varchar,@Inputdate,1) as [mm/dd/yy], CONVERT(varchar,@Inputdate,101) as [mm/dd/yyyy]
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_formats.asp
W3Schools.com
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
๐ŸŒ
Spiceworks
community.spiceworks.com โ€บ programming & development โ€บ databases & queries
Oracle SQL โ€“ Convert Format of a Date to DD/MM/YYYY - Databases & Queries - Spiceworks Community
September 25, 2014 - I have a date โ€˜25-SEP-14โ€™ and I would like to convert it to the format DD/MM/YYYY. I used the following: select TO_DATE(to_char(TO_DATE( to_char(โ€˜25-SEP-14โ€™),โ€˜DD/MON/YYโ€™)),โ€˜DD/MON/YYโ€™) from dual; It returns an error Oโ€ฆ