Skip to main content
Participating Frequently
February 18, 2020
Answered

Get day value from date field

  • February 18, 2020
  • 2 replies
  • 3186 views

Hello!
I would like to check whether the selected day is on a weekend, so like if it is saturday or sunday. So i am able to set the date format to "ddd" showing me "Sa" or "So" (German), yet when i try to grap the value from this field it gives me the selected date (like 23/02/2020 for "So").
Is there a way to grep the value "So" from the Field instead of the selected date?
Current Setup: First field selecting date by date, showing the date (23/02/2020). Second field shows the value from field 1 in the format "ddd" (So). Third field graps the getField("field2").value and gives back 23/02/2020, yet i want to check if the fieldvalue is So.

This topic has been closed for replies.
Correct answer ls_rbls

See this great tutorials by Thom Parker :

 

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript/

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2/

 

You have to read a bit but this guidance is the best starting point.

2 replies

Thom Parker
Community Expert
Community Expert
February 18, 2020

Yes, read the tutorial. 

The first thing you need to do is use the date text entry to create a date object. 

Then get the day of week with the "date.getDay()" method.

This is standard core JavaScript (not Acrobat JavaScript) so you can look up the Date object here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
February 19, 2020

Hello Thom,

after reading your tutorials i found out i first had to transform the picked dates to date objects. Since i didn't know i first have to convert the date to date objects i guess this is the reason why i didnt find it on google in the first place. your util.scand really helped me out there. After having converted it to a dateobject everything was working perfectly! Thank you!

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
February 18, 2020
Participating Frequently
February 19, 2020

thank you ls_rbls!
Actually i did find the solution in your links, i had to convert the picked date to a date object first. afterwards i could simply handle it as any javascript date object. Since your response was the first and even if the other guy is the actual writer of these tutorials i will mark your awnser as the correct one, thank you!