Skip to main content
Participant
February 14, 2024
Answered

How to calculate multiple future dates from one date

  • February 14, 2024
  • 2 replies
  • 1030 views

I am trying to enter a single pay period start date that leads to the start and end dates for the next 27 pay periods.

 

for the starting pay period I used the following script in each text field cusom calculation script adjusting the field to pull from

var d = util.scand("mm/dd/yyyy", this.getField("PPWK2End1").valueAsString);

var theTime = d.getTime () ;

var oneDay = theTime + 1*24*3600*1000;

var dd = new Date(oneDay);

event.value = util.printd("mm/dd/yyyy", dd);

 

then I used the following to get the payperiod end date 

var d = util.scand("mm/dd/yyyy", this.getField("PPWK1Start2").valueAsString);

var theTime = d.getTime () ;

var oneDay = theTime + 13*24*3600*1000;

var dd = new Date(oneDay);

event.value = util.printd("mm/dd/yyyy", dd);

 

The problem is that the dates do not populate beyond the second pay period and the calculations seem to forget there are 31 days in october when it does run correctly.

 

Please help! there has to be an easier way!

 

 

This topic has been closed for replies.
Correct answer try67

Use this:

 

var s = this.getField("PPWK1Start2").valueAsString;
if (s=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", s);
	d.setDate(d.getDate()+13);
	event.value = util.printd("mm/dd/yyyy", d);
}

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 14, 2024

Use this:

 

var s = this.getField("PPWK1Start2").valueAsString;
if (s=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", s);
	d.setDate(d.getDate()+13);
	event.value = util.printd("mm/dd/yyyy", d);
}
SNM13Author
Participant
February 14, 2024

this totally worked! 

 

I ended up going off of the first dte for each other date so there was some math involved but it works perfectly!

Nesa Nurani
Community Expert
Community Expert
February 14, 2024

You want to populate 27 days from start date?

Why not use getDate() and setDate() instead of variable oneDay?

SNM13Author
Participant
February 14, 2024

the PPWK2End is 13 days past PPWK1Start and the next row is the start of a new 2 week pay period