Solved

How to cast/Convert varchar to date

Posted on 2011-02-25
2
351 Views
Last Modified: 2012-05-11
How to convert 01012011 to a date formated as 2001-01-01?
0
Comment
Question by:kat50
2 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34981966
declare @input varchar(10)
set @input = '01012011'
select convert(varchar(10), cast(left(@input, 2) + '/' + substring(@input, 3,2) + '/' + right(@input, 4) as datetime) , 120)

0
 
LVL 40

Expert Comment

by:Sharath
ID: 34985061
Is your data in MMDDYYYY or DDMMYYYY format? and What format you are expecting?
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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 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