Example mySql IsDate Function

Here is an example mySql IsDate function using a regular expression:

CREATE DEFINER=`root`@`localhost` FUNCTION `IsDate`(var varchar(25)) RETURNS tinyint(4)
DETERMINISTIC
BEGIN
/* 05/17/2009, 5/01/2009, 5/1/2009 */

declare result tinyint;

select trim(var)

REGEXP '^([1-9]|0[1-9]|1[012])/([1-9]|0[1-9]|[12][0-9]|3[01])/(19|20)[0-9][0-9]'

into @result;

return @result;
END
Advertisements
This entry was posted in mysql. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s