我有一个名为active_plans
的表格,其中有两列:activated_date
和last_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.
但我似乎无法弄清楚如何做到这一点。
答案 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;
}