Just wanted to know how you guys handled this question. Need to know the datediff in Years and Months of two dates. The datediff function doesn't work. Look at the following example:declare @Startdate as datetime set @Startdate = '10/1/2004' select datediff(yy, @Startdate, getdate()) as Years, datediff(mm,@startdate, getdate()) as Months
This comes up with 2 Years and 21 months where the true difference is 1 yr 9 mnths. I came up with the following that will work(thanks to how SQL handles default datatypes for numbers):declare @Startdate as datetime set @Startdate = '10/1/2004' select datediff(mm, @Startdate, getdate())/12 as Years, datediff(mm,@startdate, getdate()) - (datediff(mm, @Startdate, getdate())/12)*12 as Months
A coworker says there has to be a better way of doing this but can't come up with a better solution. Off the top of my head, I can't think of any other way to make this simpler which is why I'm asking you guys to help settle the argument. Thanks, DMW