I have an Excel spreadsheet with dates formatted dd/mm/yyyy. No matter how I tell Excel to format these columns, SQL always imports them as VARCHAR(255)
When I then try to get them back into the mm/dd/yyyy format, FORMAT chokes.
This works:
This does not
Using CONVERT instead of CAST also does not work in the second case.
How can I get these dates into the mm/dd/yyy format?
When I then try to get them back into the mm/dd/yyyy format, FORMAT chokes.
This works:
Code:
DECLARE @D VARCHAR(10)
DECLARE @DDt DATE
SET @D = '3/25/2022'
SET @DDt = CAST(@D AS DATE)
SELECT FORMAT(@DDt,'dd/MM/yyyy', 'en-US' )
Code:
DECLARE @D VARCHAR(10)
DECLARE @DDt DATE
SET @D = '25/3/2022'
SET @DDt = CAST(@D AS DATE)
SELECT FORMAT(@DDt,'MM/dd/yyyy', 'en-US' )
How can I get these dates into the mm/dd/yyy format?