Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to cast/Convert varchar to date

Posted on 2011-02-25
2
Medium Priority
?
356 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 2000 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 41

Expert Comment

by:Sharath
ID: 34985061
Is your data in MMDDYYYY or DDMMYYYY format? and What format you are expecting?
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline

971 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