Best Practices in PHP Date Formatting a 4-digit year

I saw in the PHP documentation that there are two ways to format the year value in 4 digits:

Y - full numerical representation of the year, 4 digits

o is the ISO-8601 year number. This has the same meaning as Y, except that if the ISO (W) week number refers to the previous or next year, that year is used instead. (added in PHP 5.1.0)

I researched more about what ISO-8601 is and it seems more "useful" or even accurate (?) Based on php documentation. I think this is more useful because it prevents ambiguity (for example, when processing date values, for example, 1981-04-05).

But does it really matter? Is there any "best practice"? Is "o" slower, why do people use Y instead when they do nothing complicated with dates?

What specific use cases might be helpful?

Thank you for your help.

EDIT: Thanks to Jason for an example! I think why I realized this too, I wonder why not just use the “o” all the time? I think I just need to use “o” all the time for an unknown future specification that will require me to perform more complex date operations.

+5
source share
2 answers

ISO 8601 - , , . , " ISO" " ISO" , , ( , , , ).

Wikipedia . , ISO 8601 , .

, , : ? , : " [] - , [ ]".

:. --, " ISO" (o). , , , , . , .

, , Y-m-d. , date() , ISO 8601.

, o, " " ISO ( , , , W N , ).

+3

o (.. ).

Y .

:

date('Y v. o', strtotime('2012-12-31'));  // output: 2012 v. 2013

, , Y . , o / .

+5

All Articles