用php和mysql做减法
我正在开发一个 joomla 扩展,在 default.php 文件中我有这样的代码:
foreach($this->subv as $subv) {
$giorni = ((int)$subv->data_fine - (int)$subv->data_inizio);
$ore = ($giorni * 24) % 24;
echo $giorni.' : '.$ore;
}
$this->subv 是一个包含 mysql 查询结果的对象。我的问题是 echo 打印 $subv->data_fine 值,而不是减法的结果。 $subv->data_fine 和 $subv->data_inizio 包含 time() 函数的结果。 我该如何解决这个问题? 谢谢!
I am developing a joomla extension and in default.php file i have this code:
foreach($this->subv as $subv) {
$giorni = ((int)$subv->data_fine - (int)$subv->data_inizio);
$ore = ($giorni * 24) % 24;
echo $giorni.' : '.$ore;
}
$this->subv is an object that contains the result of a mysql query. My problem is that echo prints $subv->data_fine value, and not the result of the substraction. $subv->data_fine and $subv->data_inizio contain the result of time() function.
How can i resolve it this problem?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题,
$giorni
等于$subv->data_fine
,这只是意味着(int)$subv->data_inizio
计算为零。你检查过了吗?If I understand you problem correctly,
$giorni
is equal to$subv->data_fine
, which would simply mean that(int)$subv->data_inizio
evaluates to zero. Have you checked that?您可以使用 mysql 获取 2 个日期之间的差异(DATEDIFF 函数):
You can use mysql to get the difference between 2 dates (DATEDIFF function):
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff