Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with SQL date conversion

Posted on 2014-10-01
2
Medium Priority
?
205 Views
Last Modified: 2014-10-01
I have a column named birth_date which is varchar(8).  I am trying to convert this to a date and keep getting:

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

The data in the column is formatted as 01011997.

I thought this would work, but it does not and I'm not sure why:
convert(date,birth_date,101)

Any help appreciated!
0
Comment
Question by:jasonbrandt3
2 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 40355298
cast(right(birth_date, 4) + left(birth_date, 4) as date)
0
 

Author Closing Comment

by:jasonbrandt3
ID: 40355338
Perfect!!!!  Thank you so much!!!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

926 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