Solved

How to cast/Convert varchar to date

Posted on 2011-02-25
2
352 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

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…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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