ZF-5297: READ FIRST: Incorrect year returned by Zend_Date.

Issue Type: Bug Created: 2008-12-17T05:20:18.000+0000 Last Updated: 2010-12-03T14:34:05.000+0000 Status: Postponed Fix version(s): Reporter: Dolf Schimmel (Freeaqingme) (freak) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: - ZF-5296



Dear Sir/Madam,

Recently a lot of ZF users are filing a bug that Zend_Date returns the wrong year, 2009 instead of 2008. This is however expected behaviour, and NOT A BUG!

From the FAQ:

When using own formats in your code you could come to a situation where you get for example 29.12.2009, but you expected to get 29.12.2008.

There is one year difference: 2009 instead of 2008. You should use the lower cased year constant. See this example: $date->toString('dd.MM.yyyy'); instead of


From the manual

Note that the default ISO format differs from PHP's format which can be irritating if you have not used in previous. Especially the format specifiers for Year and Minute are often not used in the intended way.

For year there are two specifiers available which are often mistaken. The Y specifier for the ISO year and the y specifier for the real year. The difference is small but significant. Y calculates the ISO year, which is often used for calendar formats. See for example the 31. December 2007. The real year is 2007, but it is the first day of the first week in the week 1 of the year 2008. So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use 'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a expected behaviour depending on the used specifiers.

For minute the difference is not so big. ISO uses the specifier m for the minute, unlike PHP which uses i. So if you are getting no minute in your format check if you have used the right specifier.

Please leave this issue open at least until January 2009.


Posted by Ivo Jansch (ijansch) on 2010-01-04T07:17:05.000+0000

I think one of the reasons this confuses so many people is a misinterpretation of the ISO spec. The manual claims 'ISO uses weeknumberbasedyear, so 1-1-2010 is actually 2009 according to ISO, so it's intended behaviour'.

ISO would cease to exist if it could rightfully claim that 1-1-2010 is actually in 2009.

ISO has 2 ways of representing the year number:

1-1-2009 according to ISO 8601 Calendrial year: 2009 1-1-2009 according to ISO 8601 Weeknumberbased year: 2008

The first one is the most commonly used and the one to be used in full date representations. Zend_Date wrongfully ignores the first one and claims the second one is the only 'iso correct date'. This is wrong and causes confusion to people who use the common YYYY representation in their formatting. In my opinion, it IS a bug, and YYYY should use the ISO 8601 calendrial year representation. This means it will correctly represent 1-1-9 as '2009', and still be ISO compliant. The less common weeknumber based representation could then use a less obvious formatting string.

Posted by Matthew Weier O'Phinney (matthew) on 2010-01-04T08:42:51.000+0000

Clearly, there is (a) confusion by many, many users of the component, and (b) confusion as to implementation of the specification. Zend_Date usage should be predictable, and if it is not, should be fixed.

PHP's DateTime is how people expect Zend_Date to act. If it does not, it should be corrected.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-04T08:47:18.000+0000

It should. But, if we were to change this (no matter in a major, minor or mini release) it would break a lot of sites, without people knowing. With other BC breaks you get an exception, notice, etc. However, that would be not really possible with any change we're discussing here.

Posted by Ivo Jansch (ijansch) on 2010-01-04T08:53:31.000+0000

Dolf: I think that's ok, I doubt many people are actually using the weeknumber based year; there are hardly any use case scenario's that need this particular weird year.

Most of the people currently using it will not notice a change, in fact it might fix a problem they didn't yet know they had.

Posted by Thomas Weidner (thomas) on 2010-08-01T01:22:32.000+0000

Issue postponed for 2.0

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.