Skip to main content
Participating Frequently
November 22, 2024
Question

Date Calculation

  • November 22, 2024
  • 1 reply
  • 594 views

I have looked at dozens of posts on calculating dates and have not been able to find one that fits my scenario.  I have a date field (EDD)  that I want to use to populate another date field (ECD) 280 days prior. I would also like to be able to calculate (GA) into weeks and days.  I have uploaded a pdf of what I have done in excel  but I need to be able to do this in Adobe.  I do have DC Pro.  Please help, I am still in the learning stages of javascript.

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
November 22, 2024

Enter the following custom calculation script in the ECD field:

var EDD=this.getField("EDD").value;
if(!EDD)
{event.value=""}
else
{
var date=util.scand("mm/dd/yyyy", EDD);
date.setDate(date.getDate()-280);
event.value=util.printd("mm/dd/yyyy",date);
}

What is GA?  Weeks and days of what?

dena_5624Author
Participating Frequently
November 22, 2024

GA is gestational Age based off today date and the EDD.  Is it possible in pdf?

dena_5624Author
Participating Frequently
November 23, 2024
var ECD=this.getField("ECD").value;
if(!ECD)
{event.value=""}
else
{
var today=new Date().getTime();
var start=util.scand("mm/dd/yyyy", ECD).getTime();
var days=Math.floor((today-start)/1000/60/60/24);
var weeks=Math.floor(days/7);
var days=days%7;
event.value=weeks +" weeks, "+days+" days";
}

This is dynamic, changing with the current date.  If you want it static based on the today's date field change

var today=new Date().getTime(); to

var today=util.scand("mm/dd/yyyy", this.getField("TodaysDate").value).getTime();

 


How could I change the script to reflect years, months, & days?