Skip to content
Advertisement

Why does this date conversion cause an error? [closed]

Why does this fail?

SELECT CONVERT(DATE, '3/3/2021', 1)

Msg 241, Level 16, State 1, Line 12
Conversion failed when converting date and/or time from character string

Advertisement

Answer

Because format style = 1 means mm/dd/yy date format i.e. only a 2 digit year.

  1 = mm/dd/yy
101 = mm/dd/yyyy

You want to use the 101 style.

See the complete list of formatting styles here source

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement