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

JavaScript that identifies if date entered is weekday or weekend?

New Here ,
Nov 12, 2019 Nov 12, 2019

Copy link to clipboard

Copied

Hi Guys

 

I'm currently using Adobe Acrobat X Pro. I'm trying to create a form so that when the user inserts a date into a field a JavaScript will identify if this is a weekday or weekend. Depending on which is entered it will then add a specific rate. i.e. Weekday = £65 and Weekend =£130.

 

Can someone please help me or point me in the right direction?

 

Thanks

TOPICS
Acrobat SDK and JavaScript

Views

827

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 12, 2019 Nov 12, 2019

Copy link to clipboard

Copied

The getDay() method returns the day of the week (from 0 to 6) for the specified date.

Note: Sunday is 0, Monday is 1, and so on.

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 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

Hi

 

++ Adding to suggestion what you are looking for in your script is found in this Thom Parker's tutorial:Working with date and time in Acrobat JavaScript 

 

https://acrobatusers.com/tutorials/date_time_part2 

Use the included PDF practice file for your script which does just what you're looking for:

 

https://acrobatusers.com/assets/collections/tutorials/legacy/tech_corners/javascript_corner/tips/200... 

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 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

I forgot to add, however, that you should start with Part 1 of the turorial found here:

 

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

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 ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

Thank you for your advice and video links.

 

I'm still having difficulty finding a script that will know if the date selected is a weekday or weekend and auto populate another field with a specific rate i.e. £65 Weekday,  £130 Weekend.

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 ,
Jan 27, 2020 Jan 27, 2020

Copy link to clipboard

Copied

LATEST

Bernd provided the correct answer, but the first thing the script needs to do is to convert the text date entry into a Date Object. How this is done depends on the format. But lets just assume for this example that it's simple.

 

This script was designed to go into the Custom validate script of the date field.

 

var oMyDate = util.scand("mm/dd/yyyy", event.value);

if(oMyDate)

{

   var nDayOfWeek = oMyDate.getDay();

    if((nDayOfWeek == 0) || (nDayOfWeek == 6))

         this.getField("Rate").value = 130;

    else

         this.getField("Rate").value = 65;

}

else

    this.getField("Rate").value = 0;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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