DD/mm/yyyy in varchar(max) needs to be converted to yyyymmdd format Thought to get the experts opinion.

Below options to convert / cast didn't work:

convert(varchar(50), cast(wfm.date as datetime2), 112)
cast(cast(wfm.date as datetime2(15))as datetime)

Getting the error message for convert syntax as

Conversion failed when converting date and/or time from character string.

For cast syntax getting the error message:

Line 1: Specified scale 15 is invalid.

1 Answer 1


That's very complex. It's easier than that. Just run,

    ALTER COLUMN dt datetime2 NOT NULL;

Where dt is the name of your varchar date field. Now you have it in a date field, and you can simply,

SELECT convert(varchar, mydate, 112)
FROM foo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.