Solved

Help with SQL date conversion

Posted on 2014-10-01
2
184 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 69

Accepted Solution

by:
ScottPletcher earned 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now