Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

How to cast/Convert varchar to date

How to convert 01012011 to a date formated as 2001-01-01?
0
kat50
Asked:
kat50
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
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
 
SharathData EngineerCommented:
Is your data in MMDDYYYY or DDMMYYYY format? and What format you are expecting?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now