Zend_Date::toString() outputs the wrong year. Bug in my code, or Zend_Date?
Asked Answered
K

1

7

I'm using Zend_Date to set and get the year, but it is not being set as the correct year. I set the year as 2010, and it returns the year as 2009. What am I doing wrong? Is there a bug in Zend_Date?

$date = new Zend_Date('2010-01-03', 'YYYY-MM-dd');
echo $date->toString('MMMM d, YYYY');
//outputs January 3, 2009

The year must be being set correctly because getting the year part of the date works:

echo $date->get(Zend_Date::YEAR); //2010

Solution:

Well I got it to work...You have you use lowercase: yyyy

echo $date->toString('MMMM d, yyyy');
  • YYYY stands for the ISO Year. 2010-01-03 is week 53, day 7 of the ISO year 2009
  • yyyy stands for the actual calendar year.
Kickshaw answered 30/12, 2009 at 2:9 Comment(0)
S
12

I've ran into this problem as well.

In the Zend_Date class 'YYYY' means to a 4 digit representation of the 'ISO year' where as 'yyyy' means a 4 digit representation of the 'year'.

Sociability answered 2/1, 2010 at 14:1 Comment(2)
Yeah...I don't really know what ISO year means, so I assumed they were pretty much the same.Kickshaw
I'm not 100% sure either so I'll just present a wikipeida page: en.wikipedia.org/wiki/ISO_week_dateSociability

© 2022 - 2024 — McMap. All rights reserved.