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

Date Calculation

New Here ,
Nov 22, 2024 Nov 22, 2024

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.

TOPICS
JavaScript

Views

183

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 ,
Nov 22, 2024 Nov 22, 2024

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?

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
New Here ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

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

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 ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

The difference between EDD and today's date in weeks and days?

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 ,
Nov 22, 2024 Nov 22, 2024

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

 

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
New Here ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

Thank you, you are a true blessing.  This works perfect. 

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
New Here ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

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

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 ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

Are you assuming all months are 30 days?

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
New Here ,
Nov 22, 2024 Nov 22, 2024

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).

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 ,
Nov 23, 2024 Nov 23, 2024

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

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
New Here ,
Nov 23, 2024 Nov 23, 2024

Copy link to clipboard

Copied

LATEST

Thank you for taking the time for creating this.  It also worked perfect.  

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
New Here ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

And thank you so much it worked beautifully.

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