Reputation: 1409
I have to compare two dates, made by the zend object Zend_Date
. One is stored in a config file as a string. In order to compare the two dates I have to read from the config file the date already in there and then compare it with the Zend_Date::now()
. The code is the following:
$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/oauth2.ini', 'authorization');
$date = Zend_Date::now();
$date_old =new Zend_Date($config->authorization->date, array('date_format'=>'dd/mmm/yyyy HH.mm.ss'));
$date_old->add($config->authorization->timelapse, $date_old::SECONDS);
if ($date->isLater($date_old)) {
//Do what you have to do
}
The error message I’m getting is:
Message: Unknown dateformat type 'array'. Format 'dd/MMM/yyyy HH.mm.ss' must be a valid ISO or PHP date format string.
The string I’m giving to the Zend_Date
object is:
30/gen/2014 13.27.22
I thought the date format was right, what am I missing? Can anyone help?
Upvotes: 0
Views: 652
Reputation: 1923
The second parameter of Zend_Date constructor is a "part" string, but you pass an array. So this line should be:
$date_old = new Zend_Date($config->authorization->date, 'd/M/Y H.i.s'));
Moreover, there's another bug in your code - $date_old::SECONDS is incorrect. Try:
$date_old->add($config->authorization->timelapse, Zend_Date::SECOND);
Upvotes: 1
Reputation: 360572
As per the docs, the second argument for the Zend_Date constructor must be a STRING, you're passing in an array. Try
$date_old = new Zend_Date($config->authorization->date, 'dd/mmm/yyyy HH.mm.ss')
^^^^^---not an array
Upvotes: 1
Reputation: 43690
Your date format string isn't proper.
You want it to be d/M/Y H.i.s
per the documentation here: https://www.php.net/manual/en/function.date.php
d - is the two digit day
M - the three letter abbreviation of the month
Y - the four digit year
H - 24-hour clock with leading zeros
i - minutes with leading zeros
s - seconds
You don't need to repeat the characters to specify the number.
so this line:
$date_old =new Zend_Date($config->authorization->date, array('date_format'=>'dd/mmm/yyyy H.mm.ss'));
becomes
$date_old =new Zend_Date($config->authorization->date, 'd/M/Y H.i.s');
Upvotes: 1