Link to home
Start Free TrialLog in
Avatar of kali958
kali958Flag for United States of America

asked on

Calculate End (Payroll Date) from Start Date

I have a app that associates request time off in. Currently it display time by a pay period but I have been asked to change that to display the date they are paid.
The pay periods are every two weeks. Pay period starts on a Saturday and ends 14 days later on a Friday. Example, 11/6 to 11/19.  I was trying to find a way to calculate what the Payroll date will be for an entry based on the Start Date of the request.

I can find the week (example, week 22) in the code I have but I have no clue how to display the payroll date.  Any help would be great!
Thanks
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

For LotusScript, use NotesDateTime.AdjustDay...

      Dim endDate As New NotesDateTime(startDate)
      Call endDate.AdjustDay(14)

In Formula, use @Adjust...

      endDate := @Adjust(startDate; 0; 0; 14; 0; 0; 0);
Avatar of kali958

ASKER

I have used that before, but my concern was that if the payroll week is 14 days from 11/6 to 11/19, how do I have the dates between all display the end date of 11/19? I can take the first date and adjust that 14 but then how do I do the followings dates. Does that make sense?
You can't.  You have to have the start date to compute anything.  You must have that stored somewhere, though.
Avatar of kali958

ASKER

So it is not driven from the start date of the request. I would have to define the start date and end date of the payroll week(s) in a profile document for example?

I can not not have notes calc the payroll date from just the start date of the request?
Let's back up a bit.  I need to know the context in which the value is needed.  In your question above, you said "calculate what the Payroll date will be for an entry based on the Start Date of the request".

By "entry" do you mean a NotesViewEntry?  Is the "entry" the same as the "request"?  Are these both NotesDocuments?  Basically, I need to know what you are trying to accomplish.  For example, I can't tell if you're computing a value for a form field, a column value, a view category, or something else.
Avatar of kali958

ASKER

Here is my example
I need to take a day off - 11/17. So then I fill out a request in our Attendance Database for that day off.

The manager I was working at would like to know what payroll week that entry falls into.  So, for us. Our payroll is bi-weekly. It starts on a Saturday and ends 14 days later on a Friday. For example, the payroll period for the day off 11/17 would be 11/6 to 11/19.  They would like a view that would categorize time off by payroll week.
Currently I take the start date of the request and display it with the week that it is in.

So a view that would be :
>11/19/10
          Kali 11/17/2010  8 Hrs Vacation
I was thinking that I could take the date of the request and adjust the date somehow to calculate the payroll end date.

Does that help?
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, I missed a small point in the example above.

Add a line like this to the top of the formula...

      dayOff := NAME_OF_YOUR_FIELD;

So now it looks like...

      dayOff := NAME_OF_YOUR_FIELD;
      baseDate := [11/06/2010];
      seconds := dayOff - baseDate;
      days:= @Modulo(seconds / 86400; 14);
      startDate := @Adjust(dayOff; 0; 0; -days; 0; 0; 0);
      endDate := @Adjust(startDate; 0; 0; 13; 0; 0; 0);
      FIELD payrollWeekStartDate := startDate;
      @Text(startDate) + " - " + @Text(endDate);
Avatar of kali958

ASKER

Brilliant!!!!   That is what I was looking for. I was missing the piece of setting a beginning Payroll Date. I think I was thinking to hard about it or I was thinking I had to define each two weeks period in a profile document. I am fine with creating one base payroll date for the year.  Perfect~

Great answer Bill - thank you so much for your help and explaining this so I understood what the solution is rather then just copying something and not understanding it.
Happy to help!