Re: validating mysql bound date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks,

I ended up doing:

$incomingQuestDatePieces = explode("-", $incomingQuestDate );

if(checkdate($incomingQuestDatePieces[1],$incomingQuestDatePieces[2],
$incomingQuestDatePieces[0]))
{
	return true;
}
else
{
	return false;
}


I was just wondering since a lot of people have to verify correct format
of the date when working with mysql that there might be some built in
that is faster etc.  

Thanks though...

On Wed, 2008-03-05 at 14:34 +1100, Chris wrote:
> 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.
> 
-- 
Larry Brown <larry.brown@xxxxxxxxxxxxxxxxxxxxx>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux