Using DATEDIFF

  • I've used the DATEDIFF function several times in calculating the number of days between dates.  I'm now wanting to calculate the number of months.  Not a big deal, but what if I want to see a decimal after the value?

    E.G. DATEDIFF(mm,'5/29/04','4/1/05') = 11

    I want to see 10.9 (or what ever the value is)

    I've tried CASTING the whole thing as both a FLOAT and a NUMERIC(3,2)

    Any ideas?

  • Sure!.

    Since SQL Server has no way to know a part of what month you want to calculate, the part of 28 days or a part of 31 days, you have to tell it.

    Get a number of days by DATEDIFF, divide by 365 and multiply by 12 

    Regards,Yelena Varsha

  • Worked out GREAT!

    Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply