Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

month formula calculation

Status
Not open for further replies.

agreen

Technical User
Mar 28, 2001
1
US
I need to calculate months of service for employees. Hire date is in one cell and current date is in another. For instance, if hire date is 2/29/01 and current date is 3/28/01, months of service =0 until 3/29/01.
 
Code:
Funtion HiredMonths(YYYYHire as integer, _
                    MMHire as integer, _
                    DDHire as integer, _
                    YYYYCurr as integer, _
                    MMCurr as integer, _
                    DDCurr as integer) as integer
'* Note. \ does whole number division with no rounding
'* 2001/02/28 and 2001/02/29 = 0 = -1 + 1 + 0 + 0
'* 2001/02/28 and 2001/03/01 = 0 = -1 + 0 + 0 + 1
'* 2001/02/28 and 2001/03/28 = 1 = -1 + 1 + 0 + 1
    HiredMonths = -1 +
                + DDCurr \ DDHire _
                + 12 * (YYYYCurr - YYYHire) _
                + MMHire - MCurr
End Function
 
'* Correction for MMHire. I wish we could edit AFTER posting.
Funtion HiredMonths(YYYYHire as integer, _
MMHire as integer, _
DDHire as integer, _
YYYYCurr as integer, _
MMCurr as integer, _
DDCurr as integer) as integer
'* Note. \ does whole number division with no rounding
'* 2001/02/28 and 2001/02/29 = 0 = -1 + 1 + 0 + 0
'* 2001/02/28 and 2001/03/01 = 0 = -1 + 0 + 0 + 1
'* 2001/02/28 and 2001/03/28 = 1 = -1 + 1 + 0 + 1
'* 2001/12/28 and 2002/01/28 = 1 = -1 + 1 + 12 - 11
HiredMonths = -1 +
+ DDCurr \ DDHire _
+ 12 * (YYYYCurr - YYYYHire) _
+ MMCurr - MMHire
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top