Currently working with a company that sends info via XML which is read and inserted into our database and they've asked how they want us to send dates through, string, integer timestamp etc and it peaked my curiosity a little for me to google but not able to find the answer to the following question.
If a string for a date is sent as 03/01/2016
how does php when convert into a timestamp using strtotime()
determine the format?
UK its read as 3rd January 2016 but to the US its 1st March 2016 so how does php know to convert it to the correct region?
Does it use timezone set in the php.ini? does something have to be declared beforehand.
Never really though about it and curious to know as it would probably make my dealings a lot easier in future if information such as a date is given to me in that format
strtotime()
returns timestamp and it only parses date in specific format like "m/d/y" or "d-m-y" or "d.m.y". It is clearly state on documentation that:
Each parameter of this function uses the default time zone unless a time zone is specified in that parameter.
And regarding format accepted:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
Hope it helps...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments