cakephp每月显示条目

时间:2013-02-12 11:53:19

标签: php cakephp

我有以下脚本,它显示了我最近的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张发票?

1 个答案:

答案 0 :(得分: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").'"')
));