Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the month from a string in sql?

I have to get the month from a column which stores string in format -

Column
----------
`Feb2007'     
'Sep2008'

So if the value was 'Feb2007' then I need to get back 2 or else if the value was 'Sep2009' then I should get back 9.

Is there inbuilt function in SQL Server 2008 to achieve something like this?

like image 643
Vishal Avatar asked Sep 15 '10 21:09

Vishal


Video Answer


1 Answers

Try this:

select datepart(mm, cast('feb2008' as datetime))
like image 199
Denis Valeev Avatar answered Sep 18 '22 02:09

Denis Valeev