Re: validating mysql bound date

From: Date: Wed, 05 Mar 2008 16:08:52 +0000
Subject: Re: validating mysql bound date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-271029@lists.php.net to get a copy of this message
On Tue, Mar 4, 2008 at 8:16 PM, Larry Brown <larry.brown@dimensionnetworks.com> wrote: > Does anyone know if there is a builtin function for checking the > formatting of an incoming date to verify it is YYYY/MM/DD. I know how > to convert between formats but want a quick way to check an incoming > variable to ensure it will be handled properly by mysqld. Larry, try this: <? function verifyDate($strDate) { if(preg_match('/(19|20)?\d\d[-](0?[1-9]|1[012])[-](0?[1-9]|[12][0-3]|3[01])/',$strDate)) { return True; } else { return False; } } ?> It's also up in my snippet library here: [Demo] http://www.pilotpig.net/code-library/date-format-check.php [Source] http://www.pilotpig.net/code-library/source.php?f=date-format-check.php -- </Dan> Daniel P. Brown Senior Unix Geek <? while(1) { $me = $mind--; sleep(86400); } ?>

« previous php.general (#271029) next »