Skip to main content
Participant
October 11, 2024
Answered

Auto populate week commencing date

  • October 11, 2024
  • 1 reply
  • 563 views

I would like to populate a field with a week commencing date with Monday being the week commencing date from another date field, my dates are formatted dddd, dd mmm yyyy.

This topic has been closed for replies.
Correct answer PDF Automation Station

Assuming your other date field is called "Date", enter the following custom calculation script in the field you want to populate from it's value:

if(!this.getField("Date").value)
{event.value=""}
else
{
var date=util.scand("dddd, dd mmm yyyy",this.getField("Date").value);
var day=date.getDay();
var diff=0;
if(day==0){diff=1}
else if(day>1)
{diff=1-day}

date.setDate(date.getDate()+ diff);
event.value = util.printd("dddd, dd mmm yyyy", date);
}

1 reply

PDF Automation Station
Community Expert
Community Expert
October 11, 2024

Assuming your other date field is called "Date", enter the following custom calculation script in the field you want to populate from it's value:

if(!this.getField("Date").value)
{event.value=""}
else
{
var date=util.scand("dddd, dd mmm yyyy",this.getField("Date").value);
var day=date.getDay();
var diff=0;
if(day==0){diff=1}
else if(day>1)
{diff=1-day}

date.setDate(date.getDate()+ diff);
event.value = util.printd("dddd, dd mmm yyyy", date);
}
alun_3920Author
Participant
October 11, 2024

Thank you! That works perfectly.