Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting String todate

Status
Not open for further replies.

IanWaterman

Programmer
Jun 26, 2002
3,511
GB
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
 
Posted in wrong forum moved to MS SQL Server Programming ;-)
 
Thanks for suggestion but that still does not work

it retuns 2008-09-12 00:00:00

when correct date is 2012-09-08 00:00:00

Ian

 
I think you're stuck with using an exprssion

What you have is not really a standard date format so need to break it down into it's constituent parts to make it readable as a date



Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top