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

Adobe JavaScript Date Help

New Here ,
Mar 31, 2021 Mar 31, 2021

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.

TOPICS
PDF forms
1.9K
Translate
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 ,
Apr 19, 2023 Apr 19, 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.

 

 

Translate
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 ,
Apr 20, 2023 Apr 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 = "";

Translate
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 ,
Apr 20, 2023 Apr 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<>
Translate
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 ,
Apr 27, 2023 Apr 27, 2023

Hi Nesa,

Thankyopu for your help with this.  At first I was getting a null value from thre Date 2 field, but I sorted out by fixing the date format and this seemed to resolve that issue.   But I am now getting this error:  InvalidSetError:Set no possible, Invalid or unknown. Event.value:8: Field EeekCount:Mouse Exit

 

This is the scirpt so far:

var date1 = this.getField("Today").valueAsString;

var date2 = this.getField("Date4").valueAsString;

if(date1&&date2){

var dateT = util.scand("d-mmm-yy", date1);

var dateF = util.scand("d-mmm-yy", date2);

var diff = (dateT.getTime() - dateF.getTime())/1000;

var days = (((diff / 60) / 60) / 24)/7;

event.value = util.printf("%0.2f", days);}

else

event.value = "";

 

I am working through this but not getting very far.  Any thoughts

Translate
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 ,
Apr 27, 2023 Apr 27, 2023

If you are using script on 'Mouse Exit' then change:

event.value

to

event.target.value

Translate
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 ,
Apr 27, 2023 Apr 27, 2023
LATEST

Your wonderful....  I hope someone has told you today.

Ima working on another c=scirpt that runs through ifelse statement to pick a dollar value.   I am getting a simil;ar error.   I will use the same logic to see if it works.

Translate
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