note 125608 added to function.strtotime
| From: | BlackHatRocker@php.net | Date: | Thu, 17 Dec 2020 16:31:02 +0000 |
| Subject: | note 125608 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215989@lists.php.net to get a copy of this message | ||
*The case 30/11/-0001*
With the following note, I will report a particular behaviour of function strtotime() I want to call
it «The case 30/11/-0001». It is very common and known but never reported here. Passing the
input parameter '0000-00-00' to the function it returns a wrong and not supported
timestamp value. It can be seen with these statement
<?php echo date('d/m/Y', strtotime('0000-00-00')); // returns 30/11/-0001
?>
It seems there's no way to avoid that, but it is possibile to do workaround with if/3operator
clausole simply as follow
<?php strcmp($date "0000-00-00")? date('d/m/Y', strtotime($date) ) :
date('d/m/Y') ?>
Otherwise a simple way is to avoid to store to the DB the value '0000-00-00' and insert a
default data value (i.e. with the mySQL function NOW() which sets the date on today's date)
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.165 (proxied: 2.45.127.205)
----
Manual Page -- http://php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/125608
Del: integrated -- https://master.php.net/note/delete/125608/integrated
Del: useless -- https://master.php.net/note/delete/125608/useless
Del: bad code -- https://master.php.net/note/delete/125608/bad+code
Del: spam -- https://master.php.net/note/delete/125608/spam
Del: non-english -- https://master.php.net/note/delete/125608/non-english
Del: in docs -- https://master.php.net/note/delete/125608/in+docs
Del: other reasons-- https://master.php.net/note/delete/125608
Reject -- https://master.php.net/note/reject/125608
Search -- https://master.php.net/manage/user-notes.php