Solved

SQL 2008 - Convert string to date

Posted on 2013-01-25
5
629 Views
Last Modified: 2013-02-12
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.
0
Comment
Question by:ttist25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 38818843
0
 
LVL 6

Assisted Solution

by:esolve
esolve earned 250 total points
ID: 38818863
SET DATEFORMAT DMY

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

Author Comment

by:ttist25
ID: 38819147
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).
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 38819567
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.
0
 
LVL 1

Author Closing Comment

by:ttist25
ID: 38881745
Thanks - sorry with the delay awarding points.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question