Solved

Automatic Calculation

Posted on 2002-05-21
4
170 Views
Last Modified: 2010-05-02
I'm developing a product for my HR department that will calculate vacation time and such based on date of hire all beginning after 6 months and will vary on the length of time the employee has been here.

I'm having problems figuring out some of the logic.  Say I enter a employee who's hire date is today which would be less than six months.  An entry would be created in the database for vacation used as 0.

Now, the problem comes in how I check each employees record every day and when it comes time for their 6 month or 2 year anniversary to update the record with the appropriate amount of time.

Any help on this logic would be greatly appreciated.  
0
Comment
Question by:baddogi
  • 3
4 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 7025356
Hello,

Actually it is better to store hiring date and then perform simple calculations.

DayOf6Month = DateSerial(Year(HireDate), Month(HireDate) + 6, Day(HireDate))

Sincerely,
Crin
0
 
LVL 2

Accepted Solution

by:
Crin earned 200 total points
ID: 7025384
Of course then you will be able to find how many days, months or years one or another employee is here.

DaysCount = Now - HireDate
MonthsCount = (Year(Now) - Year(HireDate)) * 12 + _
        (Month(Now) - Month(HireDate))
 
Additional advantage of this approach is that software should not perform operations every day (just suppose computer will be off one day and every employee will lose one day of the employment history).

Sincerely,
Crin
0
 

Author Comment

by:baddogi
ID: 7025399
Thanks, I'll give that a try.....
0
 
LVL 2

Expert Comment

by:Crin
ID: 7025424
Ouch, forgot to send YearsCount formula:

Dim YearsCount as Double
YearsCount = DaysCount / 365.25

which will adequatelly take care about leap-years.

Also, for more precise MonthsCount formula you can get this one (previous calculated integer months):

Dim FirstMonthPart as Double
Dim LastMonthPart as Double
Dim MonthsCount as Double

FirstMonthPart = (DateSerial(Year(HireDate), Month(HireDate) + 1, 0) - HireDate) / _
     (DateSerial(Year(HireDate), Month(HireDate) + 1, 0) - DateSerial(Year(HireDate), Month(HireDate), 1))

LastMonthPart = (Now - DateSerial(Year(Now), Month(Now), 1) - Now) / _
     (DateSerial(Year(Now), Month(Now) + 1, 0) - DateSerial(Year(Now), Month(Now), 1))

MonthsCount = (Year(Now) - Year(HireDate)) * 12 + _
       (Month(Now) - Month(HireDate)) + _
       FirstMonthPart + LastMonthPart


Sincerely,
Crin
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now