SQL 2008 - Convert string to date

ttist25
ttist25 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
esolveSoftware Development Manager
Commented:
SET DATEFORMAT DMY

DECLARE @var NVARCHAR(100)
SET @var = '25-JAN-13'
SELECT CONVERT(varchar, CONVERT(DATETIME, @var, 101), 101)

Author

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 DBA
Most Valuable Expert 2018
Top Expert 2014

Commented:
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.

Author

Commented:
Thanks - sorry with the delay awarding points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial