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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates - Cast 1

Status
Not open for further replies.

sdempsey

Programmer
Mar 23, 2005
36
GB


I am having a problem with the dates. In my database the dates are stored as varchars in the format yyyyddmm and I would like them changed to yyyymmdd. However when I try to cast them to a date to allow me to do a convert operation. I am am getting an out of range error.

Is there an other way of doing it.

Thanks in advance


 
I would probably do:

Code:
SELECT LEFT(date, 4) + RIGHT(date, 2) + SUBSTRING(date, 5, 2)

--James
 
Is it possible that you have "garbage" data within that char field?
You can
Code:
SET DATEFORMAT YDM
select * from TABLE WHERE ISDATE ( dateCharField ) = 0
this will bring you all the fields that are not valid, and you would have to fix them.


"A long life is when each day is full and every hour wide!"
(A Jewish Mentor)
M. [hourglass]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top