Solved

Help with SQL date conversion

Posted on 2014-10-01
2
190 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:
Scott Pletcher 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

828 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