Zend Date——日差
我有下面的代码行,
$day1 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-05', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
这将返回 4
但如果给出,
$day1 = new Zend_Date('2010-02-28', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
它将返回 -27 ..我将如何得到正确的答案
I have the below line of codes
$day1 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-05', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
this will return 4
But if gave
$day1 = new Zend_Date('2010-02-28', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
it will return -27 .. how will i get right answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
返回$天;
这给出了正确的答案
return $days;
this gives the right answer
我相信问题出在你的部分字符串上。请尝试使用YYYY-MM-dd。
I believe the problem is in your part string. Try YYYY-MM-dd instead.
为了我自己的方便功能,我扩展了
Zend_Date
。我的解决方案与 Nisanth 的类似,但有一些关键区别:round()
而不是ceil()
示例代码:
I've extended
Zend_Date
for my own convenience functions. My solution is similar to Nisanth's, with some key differences:round()
instead ofceil()
1
to the resultExample code:
如果 $date 是 Zend_Date 对象,您可以使用以下命令:
或 Zend_Date 对象的其他 subXxx 函数。
If $date is a Zend_Date object you can use the following:
or the other subXxx functions of the Zend_Date object.
注册日期(稍后)和购买日期(之前)之间的天数
number of days between date of registration (later) and date of purchase (before)