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

PL Function Checking for Valid Date

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
I needed function to check if a string was a valid date and noticed that there weren't any posts after searching a bit. Here is a quick and dirty function to check for this....

CREATE OR REPLACE FUNCTION isdate(mydate text) RETURNS boolean AS
$$
DECLARE
a date;
BEGIN
if mydate is NULL then
RETURN 'f';
end if;

a := mydate::timestamp;
RETURN 't';

EXCEPTION
WHEN others THEN RETURN 'f';
END;
$$ LANGUAGE 'plpgsql';

If you have a better method, please post.

Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top