Calculating Date Interval

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I need to calculate the interval between two dates in terms of months,
and I can't figure out how to make datediff work in the decimal form that I
need...

For example,
Employee1 began on 4/1/2002 and left 3/31/2003. I need to calculate the date
interval field to say "1" (year)
Employee2 began on 4/1/2003 and left 9/30/2003. The interval field for it
should say ".5"

I'm sure there's some calculation to be done on datediff, but while I could
get "1" for Employee1, I can not for the life of me get ".5" for Employee2.
Thanks for the help!
 
Scott said:
Hi. I need to calculate the interval between two dates in terms of
months, and I can't figure out how to make datediff work in the
decimal form that I need...

For example,
Employee1 began on 4/1/2002 and left 3/31/2003. I need to calculate
the date interval field to say "1" (year)
Employee2 began on 4/1/2003 and left 9/30/2003. The interval field
for it should say ".5"

I'm sure there's some calculation to be done on datediff, but while I
could get "1" for Employee1, I can not for the life of me get ".5"
for Employee2. Thanks for the help!

DateDiff only works in integer values.

DateDiff("yyyy",#4/1/2002#,#3/31/2003#) returns "1"
DateDiff("m",#4/1/2002#,#3/31/2003#) returns "11"
DateDiff("m",#4/1/2003#,#9/30/2003#) returns "5"

To get fractions you will have to determine the difference in months, then
divide by 12 .
 
That is it perfectly! Well, almost. How do I get it to only be two decimal
places long after I divide?

Thanks
 
Back
Top