Re: Check if var has a date (timestamp or regular)

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

 



OOzy Pal wrote:
How can I check an inputed date if it is a valid date and if it is in
the form of a timestamp or regular date such as (22-07-2007 or
22/07/2007)


You could first check if the variable consists only of numbers. If so, it's likely a timestamp. If $var does consist of something other than digits, pass it to strtotime() first.



$arr_date = (
	ctype_digit($var)
	? getDate($var)
	: getDate(strtotime($var))
	);

Finally, check that the date is legitimate:

if (checkdate($arr_date['mon'], $arr_date['mday'], $arr_date['year']))
{
	...
}

brian

--
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