PHP strtotime () does not output anything

Here is my PHP code:

echo '<br />1. '.$w_time_no; echo '<br />2. '.strtotime($w_time_no); echo '<br />3. '.date('G:i', strtotime($w_time_no)); 

What I get:

 1. 0000-00-00 22:00:00 2. 3. 2:00 

Why doesn't strtotime () output anything by itself? Is there something wrong with the server settings? Server: Apache / 2.2.11 (Win32), PHP 5.2.10, MySQL client version: 5.0.51a.

+4
source share
3 answers

strtotime does not output anything, btw: it returns false in case of an error; see manual:

Return values

Returns the timestamp of success, FALSE otherwise. Prior to PHP 5.1.0, this function will return -1 on failure.

What does not output anything is echo : false is considered an empty string, and nothing is output.

the strtotime documentation also gives a valid range for dates:

Note: the actual timestamp range is usually from Fri, December 13, 1901 20:45:54 UTC to Tue, January 19, 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and the maximum values ​​for a 32-bit subscription are integer.) In addition, not all platforms support negative timestamps, so your date range can be limited no earlier than the Unix era. This means that, for example, dates until January 1, 1970, Windows, some Linux distributions, and several other operating systems will not work. PHP 5.1.0 and newer versions overcome this limitation.

'0000-00-00' is outside this range, so it is not considered a valid date; therefore, the return value is false .


As a side element to really know what is inside the variable, you can use var_dump .
As bnus used with Xdebug , you will get excellent result :-)

+10
source

0000-00-00 is not a valid date.

date () gives the result, because it interprets the input time as 0 and compensates for the time zone of your server, I would assume. I would argue that date('Ymd H:i', strtotime(...)) will give 1970-01-01 2:00

+7
source

You are mistaken strtotime() for time() .

strtotime literally corresponds to time, it needs a string to convert ..... in time.

Returns the timestamp of success, FALSE otherwise. Previously, starting with PHP 5.1.0, this function returned -1 on failure.

Thus, he cannot check this temporary line.

-1
source

All Articles