• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
4

How to calculate multiple future dates from one date

Community Beginner ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

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!

 

Maiah32906686j7xo_0-1707925387576.png

 

TOPICS
How to , JavaScript

Views

253

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 14, 2024 Feb 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);
}

Votes

Translate

Translate
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

You want to populate 27 days from start date?

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines