【发布时间】:2016-11-16 10:15:35
【问题描述】:
我正在开发 CakePHP 3.2。
我想将数据库中timestamp 的日期与CakePHP 的isThisMonth() 函数进行比较。
我列出了created 日期在1 month 内的产品。它将显示带有产品的NEW 徽章。
这是我在视图中所做的
<?php $date = new DateTime($product->created);
$date = $date->format('Y-m-d');
if ($date->isThisMonth()): ?> // error is pointing this line
<span class="new-product"> NEW</span>
<?php endif; ?>
这里$product 是错误项,created 是数据库中的时间戳列。
但这会产生错误
Call to a member function isThisMonth() on string
【问题讨论】:
标签: cakephp date-comparison cakephp-3.2