Solved

Help with SQL date conversion

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

809 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