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

Need help with date scripts from 3 fields

New Here ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Hi community, I have the following issue. 

 

I have a form where there is 3 fields for the date (expressed as week ending)

DD

MM

YY

then I have 5 other fields where I need the date to be displayed as monday to friday dates. 

 

I used to use this script where the original date was as one field and it worked nicely (example is for the monday date hence the "-4")

var date= util.scand("dd/mm/yyyy", this.getField("Week ending").value);
date.setDate(date.getDate()-4)
event.value=util.printd("dd/mm/yyyy",date)

 

How can i modify this to work with the 3 Fields?

Partial screen shot attached. 

 

thanks

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms

Views

289

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 ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

The screenshot is from the previous version, so we don't know what the actual field names are, but assuming they are "Week ending1" to "Week ending3", you can use this:

 

var date = util.scand("dd/mm/yyyy", this.getField("Week ending1").value + "/" + this.getField("Week ending2").value + "/" + this.getField("Week ending3").value);
if (date!=null) {
	date.setDate(date.getDate()-4)
	event.value=util.printd("dd/mm/yyyy",date)
} else event.value = "";

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 ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Thanks for your ideas...

So this didn't really work as intended (some fields were showing blanks)

 

I did use some of the information here and combined it with what I was using before and it worked perfectly. 

the 3 original fields as mentioned in original post were:

"DD" with value of  "01" 

"MM" with value of  "04"

"YY" with value of  "22"

all 3 of these fields are formated as "NONE" Iv'e since renamed  these fields to "DAY, MONTH, YEAR"

from these 3 fields they format 5 other fields formated as "DATE" (dd/mm/yyyy) these are :

"monday" this self populates as "28/03/2022"

"Tuesday" this self populates as "29/03/2022"

"Wednesday" this self populates as "30/03/2022"

"Thursday" this self populates as "31/03/2022"

"Friday" this self populates as "01/04/2022"

 

here is the calculation I used in the end:

var date= util.scand("dd/mm/yyyy", this.getField("Day").value + "/" + this.getField("Month").value +"/20" + this.getField("Year").value);
date.setDate(date.getDate()-4)
event.value=util.printd("dd/mm/yyyy",date)

 

this example was for the monday and only change the -4 to a -3, -2, -1, or -0 for the rest of the days. 

 

Hope this can help someone else as i've used this forum a few times for some great info. 

I might try attach a small portion of the file here in the coming days for perusal if wanted one I finish my project. 

 

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 ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

You will get an error if you clear one of those fields, though, as "28/03/" is not a valid date string, for example.

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 ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

which Fields are you refering to as only the day, month, year fields are editable the rest are locked. 

 

I could add a validation for the 3 editable fields and also mark them as required. 

 

Also for what I'm using it for and who will be using it, they will want it to be correct and use the correct numbers. This is an auditable document that I am working on so if its not used correctly then they are in the S......

 

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 ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

LATEST

Yes, I'm referring to those fields. And them being required doesn't mean they will always have a value... You need to test it carefully.

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