I am working on a query that tries to count from an exact date to an exact date. Today is 2/16/2022. Between 6/30/2020 and 2/16/2022 19 months have gone by. My DateDiff query returns 20? How can I force DateDiff function to return 19?
select datediff(month, '6/30/2020', getdate())
Advertisement
Answer
Here is the solution that worked for me.
declare @start date declare @end date set @start = '6/30/2020' set @end = '2/16/2022' select datediff(month, dateadd(day, -day(@start)+1, @start), dateadd(day, -day(@start)+1,@end))