Skip to main content
Participant
April 1, 2021
Question

Adobe JavaScript Date Help

  • April 1, 2021
  • 1 reply
  • 2112 views

I am working on a form where I want to subtract my date field from a "week" field to create a new date. I am creating a timeline for my workbook. So the equation I want is 

(Date of the Event)-(Week Form)*7=Date

 

I can get to formula to pop out the number of days but I cannot get it to format into a date field. 

 

I will need to do a similar formula but with time where I subtract hours from a "start time" so the formula will be (Start Time)-(Hours)=Time

 

Thank you in advance.

This topic has been closed for replies.

1 reply

Participant
April 20, 2023

Hi, I am looking for a similar solution using two fields, one with todays date which updates every day, and the other with a pervious date (fixed point in time)  to calculate the number of days between the two dates and then divide by 7 to get a week count. Each day you open up the page it updates the week count . You would think that it was simple logic, but not so. After having a go with my own scripts I have had to resort to reserarching this process, and modified multiple scrpits to no avail. I have a script in the new date field to calcualte that so all good as I have this in its own field.   What I am seeking to do is  to take two date fields from each other and get the the total number of days and divide by 7 to get a week count. ("Today" - "Date1A)/7  = total number of weeks in the period. 

 

I am still working on it, and if a find a solution I will post.

 

 

Nesa Nurani
Community Expert
Community Expert
April 20, 2023

Try this, it will show a result with 1 decimal:

var date1 = this.getField("Today").valueAsString;
var date2 = this.getField("Date1A").valueAsString;
if(date1&&date2){
var dateT = util.scand("mmmm d, yyyy", date1);
var dateF = util.scand("mmmm d, yyyy", date2);
var diff = (dateT.getTime() - dateF.getTime())/1000;
var days = (((diff / 60) / 60) / 24)/7;
event.value = util.printf("%0.1f", days);}
else
event.value = "";

Participant
April 20, 2023
Good evening,

Oh wow I wasn't expecting a response... its the first time I have put an issue on a support page.. I will give it a go and update...

Regards
Grant


Get Outlook for Android<>