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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Years of Service

Status
Not open for further replies.

NewToThis2

Technical User
Mar 30, 2004
62
US
C V9 - could someone possibly provide a formula for calculating years of service? The report will ask the user to enter a date range to find years of service 05, 10, 15, 20, 25, 30, 35, 40, 45, and 50.

Thanks so much!
 
Try using the DateDiff function:
DateDiff("yyyy",HirDate,Today)
MrBill
 
If the report needs to return only emnployees that will have a 5,10,15,...,50 year anniversary, you can try doing something like this:

Report menu, Record Selection, Record.
In the editor, add this:

(({Employee.Hire Date} in dateadd("yyyy",-5,minimum({?date range})) to dateadd("yyyy",-5,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-10,minimum({?date range})) to dateadd("yyyy",-10,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-15,minimum({?date range})) to dateadd("yyyy",-15,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-20,minimum({?date range})) to dateadd("yyyy",-20,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-25,minimum({?date range})) to dateadd("yyyy",-25,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-30,minimum({?date range})) to dateadd("yyyy",-30,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-35,minimum({?date range})) to dateadd("yyyy",-35,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-40,minimum({?date range})) to dateadd("yyyy",-40,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-45,minimum({?date range})) to dateadd("yyyy",-45,maximum({?date range}))) or
({Employee.Hire Date} in dateadd("yyyy",-50,minimum({?date range})) to dateadd("yyyy",-50,maximum({?date range}))))

I know this seems cumbersome, but it will get passed down to the database in SQL.

Now to show there anniversary year, create a formula like this:

numbervar i;
numbervar result;
for i := 5 to 50 step 5
do
(
if {Employee.Hire Date} in dateadd("yyyy",-i,minimum({?date range})) to dateadd("yyyy",-i,maximum({?date range})) then
(
result := i;
exit for;
)
);
result

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top