?
Solved

Automatic Calculation

Posted on 2002-05-21
4
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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