note 130478 added to function.strtotime
| From: | PaxtezJustFirstpart@gmail.com | Date: | Thu, 11 Sep 2025 16:35:51 +0000 |
| Subject: | note 130478 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222338@lists.php.net to get a copy of this message | ||
An interesting gotcha I found today which took a second to track down.
strtotime will return false with an empty string, or something that is clearly not a date. But
whitespace returns the current time.
<?php
$date = '';
$utc = strtotime($date);
var_dump($date);
var_dump($utc);
$date = 'notADate';
$utc = strtotime($date);
var_dump($date);
var_dump($utc);
$date = ' ';
$utc = strtotime($date);
var_dump($date);
var_dump($utc);
?>
Will return:
string(0) ""
bool(false)
string(8) "notADate"
bool(false)
string(1) " "
int(1757608141)
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.84.18 (proxied: 206.195.188.253)
----
Manual Page -- https://php.net/manual/en/function.strtotime.php
Edit -- https://main.php.net/note/edit/130478
Del: integrated -- https://main.php.net/note/delete/130478/integrated
Del: useless -- https://main.php.net/note/delete/130478/useless
Del: bad code -- https://main.php.net/note/delete/130478/bad+code
Del: spam -- https://main.php.net/note/delete/130478/spam
Del: non-english -- https://main.php.net/note/delete/130478/non-english
Del: in docs -- https://main.php.net/note/delete/130478/in+docs
Del: other reasons-- https://main.php.net/note/delete/130478
Reject -- https://main.php.net/note/reject/130478
Search -- https://main.php.net/manage/user-notes.php