Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
GA is gestational Age based off today date and the EDD. Is it possible in pdf?
Copy link to clipboard
Copied
The difference between EDD and today's date in weeks and days?
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
Thank you, you are a true blessing. This works perfect.
Copy link to clipboard
Copied
How could I change the script to reflect years, months, & days?
Copy link to clipboard
Copied
Are you assuming all months are 30 days?
Copy link to clipboard
Copied
Would it be possible to be more accurate? If not, 30 would be fine (it would be a close estimate).
Copy link to clipboard
Copied
I used 365/12 for the number of days in a month. Still not completely accurate due to different numbers of days per month, leap years, etc. but pretty close:
var ECD=this.getField("ECD").value;
var tdy=this.getField("TodaysDate").value;
if(!ECD || !tdy)
{event.value=""}
else
{
var today=util.scand("mm/dd/yyyy", tdy).getTime();
var start=util.scand("mm/dd/yyyy", ECD).getTime();
var totaldays=Math.floor((today-start)/1000/60/60/24);
var years=Math.floor(totaldays/365);
var daysLeft=totaldays-365*years;
var months=Math.floor(daysLeft/30.417);
var days=Math.round(daysLeft-months*30.417);
event.value=years+" years, "+months+" months, "+days+" days";
}
Copy link to clipboard
Copied
Thank you for taking the time for creating this. It also worked perfect.
Copy link to clipboard
Copied
And thank you so much it worked beautifully.