Re: No is_date() function?

From: Date: Wed, 25 Jul 2007 17:37:17 +0000
Subject: Re: No is_date() function?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-259532@lists.php.net to get a copy of this message
there is a mysterious DateTime<http://us2.php.net/manual/en/function.date-create.php>class available in php5 w/ practically no documentation at all. i dont know how they expect people to use it. but anyway; i would just build a DateTime or Time, or Date object; then you can validate it all u want :) -nathan On 7/25/07, Edward Kay <edward@labhut.com> wrote:
Thanks Lars I saw that one already but unfortunately, it doesn't help as it requires 3 inputs . What I'm shooting for is an 'is_date' function that returns true or false with no prior knowledge of what a variable might contain. Ken On Jul 25, 2007, at 10:08 AM, Lars Haßler wrote:
Hi, there is a function to check a valid date: http://de3.php.net/ manual/de/function.checkdate.php may help
Hi I wrote a serialization function to turn arbitrary PHP variables into Macintosh plist compatible XML but see that there is no "is_date" tester as there is for bool, object, array etc. Is there a relatively simple (and robust) way to detect if a variable is a date? For example: $person = array('name'=>'bob', 'sex'=>'male', 'date_of_birth'=> $someDateHere); Thanks for any help Ken
You won't find one. This is because PHP does not have a native type for dates.. If you have a string e.g. 23-Mar-1985, you can use regexp to match or extract the various parts. You could then use the checkdate function to ensure it is a valid date (e.g. not 31st Feb or similar). Edward PS: Please don't top post on mailing lists. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#259532) next »