查询学说中的日期

时间:2013-04-01 17:01:04

标签: date symfony doctrine-orm doctrine symfony-2.1

我有一个名为active_plans的表格,其中有两列:activated_datelast_billed_at。基本上,我想创建一个查看这两列的查询:

select all from active_plans 
          where last_billed_at = null AND activated_date + 1 month = today, 
          or if last_billed_at + 1 month = today.

但我似乎无法弄清楚如何做到这一点。

1 个答案:

答案 0 :(得分:0)

我做了很多不同的事情:     公共函数getBillToday()     {         $ activePlans = $ this-> entityManager                  - > createQuery('SELECT adp FROM adp                     在哪里adp.activationDate IS NOT NULL')                  - >的getResult();         $ data = array();

    foreach ($activePlans as $plan) {
        $recur = $plan->getPlan()->getRecurringInMonths();
        $nextBillTime = strtotime('-'.$recur.' months', time());
        $nextBill = date('Y-m-d', $nextBillTime);
        $activationDate = $plan->getActivationDate();
        $lastBilledAt = $plan->getLastBilledAt() != NULL ? $plan->getLastBilledAt()->format('Y-m-d') : 0;
        if ($activationDate == $nextBill || $lastBilledAt == $nextBill) {
            $data[] = $plan->getId();
        }
    }

    return $data;
}