Re: validating mysql bound date

From: Date: Wed, 05 Mar 2008 03:34:24 +0000
Subject: Re: validating mysql bound date
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-270995@lists.php.net to get a copy of this message
Larry Brown wrote:
Its been a long week already... YYYY-MM-DD. On Tue, 2008-03-04 at 20:16 -0500, Larry Brown 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.
I normally provide dropdown fields for each (except the year which is a text-field) and put it together how I need it. Validate each part separately and you're off and racing. If you accept any date you'll probably have to split it up first but the principles will be the same. $date = '0000-00-00'; // if they didn't use exactly two dashes? invalid if (substr_count($date, '-') !== 2) { die("Invalid date"); } list($year, $month, $day) = explode('-', $date); if (strlen($year) != 4) { die("Invalid year"); } and so on. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#270995) next »