Re: Check if var has a date (timestamp or regular)
| From: | brian | Date: | Mon, 06 Aug 2007 14:29:17 +0000 |
| Subject: | Re: Check if var has a date (timestamp or regular) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-260235@lists.php.net to get a copy of this message | ||
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