Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

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

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

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?
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? winky smile

Ian, I feel sorry for you having to deal with this.

Amazing!

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close