How does PHP determine date format for a strtotime() call

Rlemm1991

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

d.coder

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php?

From Dev

PHP: Add some milliseconds to a date() with strtotime()

From Dev

PHP Converting Integer to Date, reverse of strtotime

From Dev

PHP date & strtotime adding 12 minutes?

From Dev

PHP strtotime() with date() issue with year field

From Dev

Using strtotime to format date() with AM/PM

From Dev

String date to time in PHP - strtotime "loses hours"

From Dev

strtotime is not working proper in php for future date?

From Dev

format of date string for strtotime() function in php

From Dev

PHP date conversion using strtotime

From Dev

Php: Change language in date/strftime/strtotime

From Dev

How to check format of Date in PHP?

From Dev

Why does PHP date('m', strtotime('-1 months')) not work correctly for today? 07/31

From Dev

PHP: strtotime revered return strange date?

From Dev

PHP strtotime() "noon" must go before date

From Dev

PHP - Why does time() return different number of seconds than strtotime(date())

From Dev

How to handle date format in PHP

From Dev

how to change date format of datetime format in php

From Dev

PHP: Add some milliseconds to a date() with strtotime()

From Dev

Formatting date using PHP strtotime

From Dev

how to convert date format in php?

From Dev

PHP date returning blank for Year "2090" with strtotime

From Dev

how to overwrite date to 1st of month php strtotime and date

From Dev

How to convert this date format to PHP

From Dev

How to format php date using this format

From Dev

format of date string for strtotime() function in php

From Dev

How to display date format in php?

From Dev

Check a date interval with strtotime in php

From Dev

PHP date format and strtotime

Related Related

  1. 1

    What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php?

  2. 2

    PHP: Add some milliseconds to a date() with strtotime()

  3. 3

    PHP Converting Integer to Date, reverse of strtotime

  4. 4

    PHP date & strtotime adding 12 minutes?

  5. 5

    PHP strtotime() with date() issue with year field

  6. 6

    Using strtotime to format date() with AM/PM

  7. 7

    String date to time in PHP - strtotime "loses hours"

  8. 8

    strtotime is not working proper in php for future date?

  9. 9

    format of date string for strtotime() function in php

  10. 10

    PHP date conversion using strtotime

  11. 11

    Php: Change language in date/strftime/strtotime

  12. 12

    How to check format of Date in PHP?

  13. 13

    Why does PHP date('m', strtotime('-1 months')) not work correctly for today? 07/31

  14. 14

    PHP: strtotime revered return strange date?

  15. 15

    PHP strtotime() "noon" must go before date

  16. 16

    PHP - Why does time() return different number of seconds than strtotime(date())

  17. 17

    How to handle date format in PHP

  18. 18

    how to change date format of datetime format in php

  19. 19

    PHP: Add some milliseconds to a date() with strtotime()

  20. 20

    Formatting date using PHP strtotime

  21. 21

    how to convert date format in php?

  22. 22

    PHP date returning blank for Year "2090" with strtotime

  23. 23

    how to overwrite date to 1st of month php strtotime and date

  24. 24

    How to convert this date format to PHP

  25. 25

    How to format php date using this format

  26. 26

    format of date string for strtotime() function in php

  27. 27

    How to display date format in php?

  28. 28

    Check a date interval with strtotime in php

  29. 29

    PHP date format and strtotime

HotTag

Archive