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

change char to datefield and then validate the date

Status
Not open for further replies.

kizziebutler

Programmer
Apr 28, 2005
81
0
0
GB
I have a field (date_booked) that contains dates, it an char field. I like to be able to convert if from a char field to a datetime field and then validate it using ISDATE to check if the date is valid.

Select date_booked =
case ISDATE(date_booked)
when 0 then convert(vharchar(25), date_booked, 120)
when 1 then convert(varchar(25),Getdate(),120)
end
from sbase_local.cellularlocal..jobs
 
Sorry I thought the question was clear. I have to validate the field date_booked to see if it contains validate dates, but unfortunately the field is a char field. I am exporting all the data, using bcp but what I need to do is write a function that checks the date_booked field to see if it contains validate date. I try to use the ISDATE but the field (date_book) is a char field and I need to somehow validate the data store in this field to see if it contains validate date, if the date is validate then output the date as YYYY/MM/DD HH:MM:SS if it is not validate then replace this with the getdate(). I would really appreciate some help and suggestions. Thank you.
 
jbenson001 asked what the question because it seems you posted valid SQL that will do what you are looking for and could be incorporated into a SP, a view, a function, whatever.

So, what is the problem with what you posted?

TJR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top