PHP: strtotime() - consistent results

skij
skij used Ask the Experts™
on
How venerable is this to the settings of the server?
echo date('F j, Y',strtotime('2015-2-7'));

Open in new window

In some locations, 2015-2-7 could be considered February 7, while in other places it could be considered to be July 2.  What is the most foolproof way to create a timestamp from  a day, month and year?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Use the ISO-8601 standard for all internal representations of date/time values.  Reformat for printing or display.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Test some with Practical Application #7.  You will find that dashes and slashes have different meanings to strtotime().
http://php.net/manual/en/datetime.formats.php
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
By convention the format 2015-07-20 (uses dashes) is in UTC format (yyyy-mm-dd)

If you use slashes (2015/20/07) then it is in US format (yyyy/mm/dd)
Most Valuable Expert 2011
Top Expert 2016

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial