After some messing around with strtotime() in PHP I noticed that it gives a valid timestamp back when you pass in spaces and or dots.
var_dump(strtotime(" "));
var_dump(strtotime("."));
var_dump(strtotime(". .. .. .. .... .. . .. ."));
produces:
int 1443009652
int 1443009652
int 1443009652
Why does PHP see this as valid?
Definition and Usage The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
Description ¶ time(): int. Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Note: Unix timestamps do not contain any information with regards to any local timezone.
Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );
We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.
The simplest answer is some of them are false
y
var_dump(DateTime(false)); // date shown is current time
My bet is that the parser (which is trying to clean up a wide variety of acceptable inputs) strips the periods out (that are not being used as a delimiter), leaving only an empty string. It's the only explanation that makes sense.
echo strtotime('1.1.2000'); // outputs 946681200
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With