Discrepancy in the data from datediff function

Hi all, I'm trying to use the datediff() function to get difference between 2 dates in months -

But I am facing some issue in the output. For example, if we are trying to find out difference between 2022-05-15 and 2022-07-01 in months, ideally it should be 1 but it is showing 2. Please let me know how to fix this, or if there's a way around for the same.

Thanks

Hi @neelesh.priyadarshi
The result is coming from your database, so you should do something like:

select floor(datediff(day, '2022-05-15', '2022-07-01')/30) as total_active_month

Hi,
Thanks, I tried that, but this creates an issue when the month in consideration is of 31 days.

@neelesh.priyadarshi Okay, then try searching for a solution on stackoverflow.com, since it's really not specific to Metabase, but the database type you're using.

maybe you can try
select timestampdiff(month,'2022-05-15', '2022-07-01');