Convert varchar in mon-yy format to datetime in SQL server

Is there an easy way to convert the date stored in varchar in mon-yy format (for example, "Feb-09") to datetime, which converts any invalid values ​​to null.

I am currently using string manipulation in conjunction with the case argument, but this is rather cumbersome.

+3
source share
3 answers

For real values, you can just put a day on it, and this is the full date:

convert(datetime,'01-' + 'Feb-09',120)
+9
source

It will do it.

SELECT convert(datetime,'01-' + 'Feb-09',120)
+2
source
CONVERT( DATETIME, "Feb-09", 64, 7 )
0

Source: https://habr.com/ru/post/1703904/


All Articles