devorye devorye - 4 months ago 22
PHP Question

Difference between 2 dates in months Yii2

I have a question here. I need to get the difference betweeen 2 dates in months by using Yii2. I know that I should use

format it in months
, but it's not working. Could someone help me to solve the problem?

Here is my line that I need to count the difference in months:

$holidays = 'floor(datediff(curdate(), employment_date))';

Thanks for any help

Answer Source

Since you are using mysql, you can use TIMESTAMPDIFF:

$holidays = '(TIMESTAMPDIFF(MONTH, employment_date, curdate()))';