Click here to Skip to main content
15,037,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to convert Months names which are in columns to date format like '2/1/2021','3/1/2021' and so on..

Feb'21, Mar'21, Apr'21, May'21, Jun'21, Jul'21, Aug'21, Sep'21, Oct'21,

What I have tried:

case when 'Feb'21' then 2/1/2021 end
i tried with case statement but its not correct way
Updated 26-May-21 21:40pm

You need to parse the text, split the two fields and use some lookup table to convert the month. Or see sql parse date - Google Search[^].
TO be honest, you'd probably be better off doing that in a presentation language where you have access to the users context information - including his language and date format preferences - SQL string handling isn't good, and while processing English month names is relatively trivial (as Richard has said, a lookup table will do it) it becomes a lot more complicated if you need to handle any international month names.
Plus, it gets a bit nasty with two digit years, as the data you have to prefix them with could be in two different centuries - and you have to decide which based on some rule you have to invent!

If you do decide to do it in SQL, then I'd strongly suggest writing a user function to do the conversion as it will make your life a load easier ...
User-Defined Functions - SQL Server | Microsoft Docs[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900