Re: Way to test if variable contains valid date

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

 



Or you could use a regular expression:

$probe = '2000-01-01';
$found = preg_match('/(19|20)\d\d[- \.](0[1-9]|1[012])[-
\.](0[1-9]|[12][0-9]|3[01])/', $probe);
var_dump($found==1);

Erwin

2012/7/3 shiplu <shiplu.net@xxxxxxxxx>

> >
> >
> > I want to thank you, Daniel, for this help.  - I was looking for an
> > "isarray" type function
>
>
> There is no such function or facility in php. However you can check date in
> string by DateTime object also
>
> try {
>     $date = new DateTime('2000-01-01');
> } catch (Exception $e) {
>     echo $e->getMessage();
>     exit(1);
> }
>
> Check php.net/datetime.construct
>
> --
> Shiplu.Mokadd.im
> ImgSign.com | A dynamic signature machine
> Innovation distinguishes between follower and leader
>

[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