I am trying to write a query in order to get all the data whose date is greater than 11 months old or less than 12 months old. I have tried the query below which returns date difference in days. Is there any way I can check on months ??
$qb ->select("pj,DATE_DIFF(CURRENT_TIME(), pj.date) as dt)
->from("PrevJbs", "pj");
There is Mysql-function PERIOD_DIFF
which can do it easier, but it operates PERIODS
$qb ->select("
pj,
PERIOD_DIFF(DATE_FORMAT(CURRENT_TIME(), '%Y%m'), DATE_FORMAT(pj.date, '%Y%m')) AS dt
")
->from("PrevJbs", "pj");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With