note 92691 added to datetime.construct

From: Date: Tue, 04 Aug 2009 12:09:53 +0000
Subject: note 92691 added to datetime.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-159078@lists.php.net to get a copy of this message
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 ---- Server IP: 80.64.47.13 Probable Submitter: 80.37.14.51 ---- Manual Page -- http://www.php.net/manual/en/datetime.construct.php Edit -- https://master.php.net/note/edit/92691 Del: integrated -- https://master.php.net/note/delete/92691/integrated Del: useless -- https://master.php.net/note/delete/92691/useless Del: bad code -- https://master.php.net/note/delete/92691/bad+code Del: spam -- https://master.php.net/note/delete/92691/spam Del: non-english -- https://master.php.net/note/delete/92691/non-english Del: in docs -- https://master.php.net/note/delete/92691/in+docs Del: other reasons-- https://master.php.net/note/delete/92691 Reject -- https://master.php.net/note/reject/92691 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159078) next »