Solved

SQL 2008 - Convert string to date

Posted on 2013-01-25
5
607 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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