Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql. date difference in months

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");
like image 953
Salman Avatar asked Feb 10 '26 19:02

Salman


1 Answers

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");
like image 147
M0rtiis Avatar answered Feb 12 '26 15:02

M0rtiis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!