note 92691 deleted from datetime.construct by danielc

From: Date: Wed, 05 May 2010 03:39:02 +0000
Subject: note 92691 deleted from datetime.construct by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168945@lists.php.net to get a copy of this message
Note Submitter: alvaro at demogracia dot com ---- Like in many other date functions, PHP calculates the correct value for out-of-range input, so the constructor won't necessarily throw an exception when fed with wrong dates: <?php date_default_timezone_set('Europe/Madrid'); try{ $d1 = new DateTime('2009-02-28'); echo $d1->format(DATE_RSS) . "\n"; }catch(Exception $e){ echo "Invalid date: 2009-02-28\n"; } try{ $d2 = new DateTime('2009-02-29'); echo $d2->format(DATE_RSS) . "\n"; }catch(Exception $e){ echo "Invalid date: 2009-02-29\n"; } try{ $d3 = new DateTime('2009-02-xx'); echo $d3->format(DATE_RSS) . "\n"; }catch(Exception $e){ echo "Invalid date: 2009-02-xx\n"; } ?> Sat, 28 Feb 2009 00:00:00 +0100 Sun, 01 Mar 2009 00:00:00 +0100 Invalid date: 2009-02-xx

« previous php.notes (#168945) next »