Link to home
Start Free TrialLog in
Avatar of dstjohnjr
dstjohnjrFlag for United States of America

asked on

SQL Stored Procedure to validate date

I am looking to design a SQL Stored Procedure (SQL Server 2000) that will validate a date.  Now, before you think this is a normal date, here is a more specific definition of what I am looking to validate.

The field in the DB is a varchar field (10 chars I think) and the date format is:  YYYYMMDD (i.e. 20071015)

It might sound a little whacked (and it is) but this is what I have to work with.

Of course, the SQL SP would have a parameter that would need to be passed to it, that being the date string as outlined above.

TIA for any help!
Avatar of Yveau
Yveau
Flag of Netherlands image

What you are looking for is the buildin SQL function IsDate() !

returns 1 if the argument is a valid date, 0 otherwise.

Hope this helps ...
ASKER CERTIFIED SOLUTION
Avatar of Yveau
Yveau
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... but that will return 1 to '20071939' as well ... and that really is not a valid date.

Hope this helps ...
... you could combine the two:
... oops that is what mmcdermaid did
... sorry, too early I guess :-)

The '20071939' thing is not true as I said before !
Avatar of nmcdermaid
nmcdermaid

I didn't check if ISDATE('20071939') = 0 or 1.... maybe the questioner can tell us :)
It's a 0, so your AND clause filters these kinds of values.
That's the part I missed ...
Avatar of dstjohnjr

ASKER

Thanks for the assistance experts and sorry for the delay.