Zend_Date: Difference in days from now() to 1899-30-12

View: New views
3 Messages — Rating Filter:   Alert me  

Zend_Date: Difference in days from now() to 1899-30-12

by Nogyara :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
just trying to use Zend_Date's for the first time. Really like the API and how it works but now I'm a bit stuck now. I need to calculate difference between current date and 1899-30-12 (because of some Excel prosessing) and return difference in days (in other words, number of days since 1899-30-12 to today).
Date subtraction works fine using Zend_Date->subDate(), however, I don't know how to convert the result date to number of days (didn't find answer in Zend_Date API docs either in this list's archive). And I can't use UNIX timestamps for calculation of difference because the date 1899-30-12 is out of its range.
Any suggestions, please? Thanks in advance

Re: Zend_Date: Difference in days from now() to 1899-30-12

by thomasW :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You CAN use timestamps.
The timestamps which are used by Zend_Date are not limited to UNIX.
So you can calculate what you need with the getTimestamp() functions from
Zend_Date.
It is also mentioned within the manual.

Greetings
Thomas Weidner, I18N Team Leader
http://www.thomasweidner.com

----- Original Message -----
From: "Nogyara" <richie.blue@...>
To: <fw-i18n@...>
Sent: Sunday, February 17, 2008 8:35 PM
Subject: [fw-i18n] Zend_Date: Difference in days from now() to 1899-30-12


>
> Hi all,
> just trying to use Zend_Date's for the first time. Really like the API and
> how it works but now I'm a bit stuck now. I need to calculate difference
> between current date and 1899-30-12 (because of some Excel prosessing) and
> return difference in days (in other words, number of days since 1899-30-12
> to today).
> Date subtraction works fine using Zend_Date->subDate(), however, I don't
> know how to convert the result date to number of days (didn't find answer
> in
> Zend_Date API docs either in this list's archive). And I can't use UNIX
> timestamps for calculation of difference because the date 1899-30-12 is
> out
> of its range.
> Any suggestions, please? Thanks in advance
> --
> View this message in context:
> http://www.nabble.com/Zend_Date%3A-Difference-in-days-from-now%28%29-to-1899-30-12-tp15532300s16154p15532300.html
> Sent from the Zend I18N/Locale mailing list archive at Nabble.com.


Re: Zend_Date: Difference in days from now() to 1899-30-12

by Nogyara :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Thomas,
thanks a lot for your reply.
Actually, I've read this part of manually before I asked and also tried to use timestamps before but with no success. So I though it can't be used for such calculations in addition, when I've read API description of getTimestamp() method:
"Returns this object's internal UNIX timestamp (equivalent to Zend_Date::TIMESTAMP)."
Problem was probably that I tried to subtract those two timestamps and the result convert to Zend_Date, what I guess can never work.
Now when you showed me that timestamps are really correct way to go, I tried it again.. and it worked without problems. For anyone solving similar problem, this fragment of code works fine:

//create date object from UNIX timestamp of period's start date for current locale
$oDateCurrent = new Zend_Date(strtotime($aPeriod['start']['date']), Zend_Date::TIMESTAMP, Richie_App::getInstance()->getLocale());
//date object needed for counting date for binary excel (see later)
$oDateExcelBase = new Zend_Date('1899-12-30', Zend_Date::ISO_8601);
//get difference of both dates in days
$iDateDiffernceDays = floor(($oDateCurrent->getTimestamp() - $oDateExcelBase->getTimestamp()) / (24 * 60 * 60));

Thanks again Thomas
Best regards

Richard


Thomas Weidner-2 wrote:
You CAN use timestamps.
The timestamps which are used by Zend_Date are not limited to UNIX.
So you can calculate what you need with the getTimestamp() functions from
Zend_Date.
It is also mentioned within the manual.