SQL 2008 - Convert string to date

Good morning,

I have a number of string fields that represent dates.  I would like to convert them to date fields like so:

From: 25-JAN-13
To: 01/25/2013

Thanks in advance for any help.
Who is Participating?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
esolveSoftware Development ManagerCommented:

SET @var = '25-JAN-13'
SELECT CONVERT(varchar, CONVERT(DATETIME, @var, 101), 101)
ttist25Author Commented:
Thanks for the responses guys.  

Angel - I did a brief review of the article you sent.  Thank you.  I will need to review it again (probably several times) to get it through my thick skull before I try to implement it.  :)

Esolve - thanks for your response as well.  In your example you use the date from my example (25-JAN-13).  I should've been more specific and said I am trying to "batch" convert the dates that are in the format dd-mmm-yy to mm/dd/yyyy (although after reading the article I'm not sure the slash format is what I want to do).  

Thanks again for your help and especially the article (teach a man to fish although a fish would taste great right now).
Scott PletcherSenior DBACommented:
If you're going to store dates in a varchar format, use 'YYYYMMDD'.  This format is always interpreted correctly, so you never need any error-prone and time-consuming conversion codes to use it.
ttist25Author Commented:
Thanks - sorry with the delay awarding points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.