Smart questions
Smart people
 Find A ForumFind An Expert
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips now!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Just copy and paste the

#### Feedback

"...your web site's great! I've been using this system for almost a year now and find it really, really helpful. The people have been helpful in answering just about any question you post in the forums..."

#### Geography

Where in the world do Tek-Tips members come from?

# Convert Numeric String to date

 Forum Search FAQs Links Jobs Whitepapers MVPs
 IanWaterman (Programmer) 26 Jun 12 9:26
 I have a string date stored as ddmmyy When I use cast with the field = 080912 Cast(EffectiveDate as Date) I get 2008-09-12 00:00:00 I have solved this by breaking down cast(SUBSTRING(EffectiveDate,5,2)+SUBSTRING(EffectiveDate,3,2)+SUBSTRING(EffectiveDate,1,2) as DATE)EffDate, This gives me the correct result but looks a bit convoluted is there a more efficient way? Thank you Ian
 bborissov (Programmer) 26 Jun 12 9:50

#### CODE

DECLARE @Test varchar(20)
SET @Test = '080912'

SELECT CAST(@Test as date)
Of course you ALWAYS should check if the string is correct date, because this:

#### CODE

DECLARE @Test varchar(20)
SET @Test = '083112'

SELECT CAST(@Test as date)
will raise an error

Borislav Borissov
VFP9 SP2, SQL Server

 SkipVought (Programmer) 26 Jun 12 10:49
 Wow! Why would any thinking person store a date with either MONTH or DAY in the first position. WORTHLESS for sorting, not to mention the inability to do date arithmetic with TEXT! Also it seems suprising that any company in the twentyfirst century would be using TWO CHARACTER DATES. Shouldn't that have been addressed prior to Y2K? Are they still using a 360 or have they stepped up to a 370? Hollerith cards or green screens? Ian, I feel sorry for you having to deal with this. Amazing! Skip, Just traded in my old subtlety... for a NUANCE!
 bborissov (Programmer) 26 Jun 12 11:38
 OOOPS!!! Sorry, I just read what you want as a result. Borislav Borissov VFP9 SP2, SQL Server
 gmmastros (Programmer) 26 Jun 12 11:53
 There's likely to be a dozen ways to do this, but every method will seem convoluted. A string of 6 digits will always be interpreted as ymd. Therefore, complex and convoluted is the only way to go. -George Microsoft SQL Server MVP My Blogs SQLCop twitter "The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!