1

我有以下脚本,它显示了我最近的 5 张发票,如下所示:

<?php 
  $year = (int)(substr($invoice['Invoice']['invoice_date'], 0, -6));
  $month = (int)(substr($invoice['Invoice']['invoice_date'], 5, -3));
?>
<?php if($count < 5) : ?>

这现在显示 5 个最新的发票,无论它们是在哪个月份到期的。如何调整/更改此代码段以向我展示当月的 5 张发票?

4

1 回答 1

3

为什么不使用cakephp time helper.

<?php $year  = $time->format('Y',$invoice['Invoice']['invoice_date']); ?>
<?php $month = $time->format('m',$invoice['Invoice']['invoice_date']); ?>

对于您本月的最新记录,请尝试以下解决方案。

<?php

$this->Invoice->find('all', array
(
    'conditions'=> array('DATE_FORMAT(Invoice.invoice_date,"%m") = "'.date("m").'"')
));
于 2013-02-12T11:57:57.963 回答