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

Javascript to Auto Populate Day of the Week Based on Two Variables

New Here ,
Dec 05, 2022 Dec 05, 2022

I have searched everywhere, but can't find anything to help me get started on the Script.  I would like a timesheet to auto populate the correct date based on the pay period and what week of the pay period, week 1 or week 2.  Pay Periods are based on the Federal OPM Pay Calendar.

 

User inputs:  Pay period and week of the pay period

Desire Outcome: Auto popluates Sundays (start of work week) date on time sheet

Timesheet Snipet.jpgexpand image

The timesheets are completed weekly.  I have thought about reversing the inputs.  User enters start date and the script auto popluates the week and pay period.  Which ever is the easiest.  First timer on script, but thanks to this community, I have knocked out everything else.  Thank you!

 

TOPICS
How to , JavaScript , PDF forms
602
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 ,
Dec 05, 2022 Dec 05, 2022
LATEST

if you search on this forum for "add days to date", you'll find plenty of code that will get you started.    Searching on "timesheet dates" will provide more results, maybe even better ones for this question.

In fact, this exact question has been asked many times. 

 

There are three parts to any time/date calculation 

1) Convert a time/date string to a Date object

2) Perform calculation

3) Format resulting Date object/data into a date/time string.

 

Let's skip the first and last part and concentrate on the calculation using the date object. 

This code adds one day (in place) to the date object.

 

var dtMyDate = ...

dtMyDate.setDay(dtMyDate.getDay()+1);

 

 That's all there is to incrementing days. 

 

You'll find more info on date and times here:

https://www.pdfscripting.com/public/Date-and-Time-Handling.cfm

https://acrobatusers.com/tutorials/date_time_part1/

https://acrobatusers.com/tutorials/date_time_part2/

 

 

 

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

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