Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Monthly Time Sheet Dates

Avatar

Level 2

I am building a monthly time sheet. I need all the dates to populate once the initial date is chosen by the user. I have this working properly for each month that has 31 days. For months with 30 days, it populates the first day of the next month. How do I make sure that the only the dates for the month selected are populated?

Any help is appreciated!

Tracy

1 Accepted Solution

Avatar

Correct answer by
Level 10

Ok,

here's a modifiedversion of your form.

It uses a dynamic table, which has sevaral benefits like very slim calculation scripts and a small file size.

https://acrobat.com/#d=gTlaptez8XA2A5*0it4Wow

View solution in original post

12 Replies

Avatar

Level 10

Hi,

you need a script to determine the number of days in the current month.

This can be done with FormCalc.

Here an example. Assuming you have two datefields and one text field to display the number of days.

Put this script into the calculate event of the text field.

When the user selects a any date in DateField1 the script determines the first and last day in the current month and will display the related dates in the date fields.

var StartDate = Ref(DateField1)

var EndDate = Ref(DateField2)

 

var MonthStart = Date2Num(StartDate.formattedValue, "DD.MM.YYYY")

var nDay = Num2Date(MonthStart, "DD")                                                  ; Current Day

var nMonth = Num2Date(MonthStart, "MM")                                        ; Current Month

var nYear = Num2Date(MonthStart, "YYYY")                                        ; Current Year

var nFirstDay = Date2Num(Concat("01.",nMonth, ".", nYear), "DD.MM.YYYY")                    ; First Day in the curren month

var nLastDay

var nCountDays = nFirstDay

StartDate.rawValue = Num2Date(nFirstDay, "DD.MM.YYYY") ; Set first day of month as start date

 

; Determine number of days in the current month

var nMonthCheckStart = Num2Date(nFirstDay, "MM")

var nMonthCheckEnd

for i=0 upto 31 step 1 do

          nCountDays = nCountDays + 1

          nMonthCheckEnd = Num2Date(nCountDays , "MM")

          if(nMonthCheckStart == nMonthCheckEnd) then

                    nLastDay = nCountDays

          endif

endfor

 

EndDate.rawValue = Num2Date(nLastDay, "DD.MM.YYYY") ; Set lastday of month as end date

$.rawValue = Num2Date(nLastDay, "DD") ; Set number of days this month

Avatar

Level 2

Hello!

Thank you for your response, but I can not get it to function properly.

I added a text field to calculate the number of days.  Here is the script I placed in the text field:

form1.commentSub.NoofDays::calculate - (FormCalc, client)

var StartDate = Ref(SubPg1.tableSub.Table1.Row1.Date1)

var EndDate = Ref(SubPg1.tableSub.Table1.Row2.Date2)

var MonthStart = Date2Num(Date1.formattedValue, "MM/DD/YYYY")

var nMonth = Num2Date(MonthStart, "MM")                                                                                                     ; Current Month

var nDay = Num2Date(MonthStart, "DD")                                           ; Current Day

var nYear = Num2Date(MonthStart, "YYYY")                                        ; Current Year

var nFirstDay = Date2Num(Concat(nMonth,"01", nYear), "MM/DD/YYYY")        ; First Day in the current month

var nLastDay

var nCountDays = nFirstDay

StartDate.rawValue = Num2Date(nFirstDay, "MM/DD/YYYY") ; Set first day of month as start date

; Determine number of days in the current month

var nMonthCheckStart = Num2Date(nFirstDay, "MM")

var nMonthCheckEnd

for i=0 upto 31 step 1 do

          nCountDays = nCountDays + 1

          nMonthCheckEnd = Num2Date(nCountDays , "MM")

          if(nMonthCheckStart == nMonthCheckEnd) then

                    nLastDay = nCountDays

          endif

endfor

EndDate.rawValue = Num2Date(nLastDay, "MM/DD/YYYY") ; Set lastday of month as end date

$.rawValue = Num2Date(nLastDay, "DD") ; Set number of days this month

In the date field where the user selects the date. I have this:

form1.SubPg1.tableSub.Table1.Row1.Date1::exit - (FormCalc, client)

var dayNum = Date2Num($.formattedValue,"MM/DD/YY")

Row2.Date2.rawValue = Num2Date(dayNum+1,"MM/DD/YY")

Row3.Date3.rawValue = Num2Date(dayNum+2,"MM/DD/YY")

Row4.Date4.rawValue = Num2Date(dayNum+3,"MM/DD/YY")

Row5.Date5.rawValue = Num2Date(dayNum+4,"MM/DD/YY")

Row6.Date6.rawValue = Num2Date(dayNum+5,"MM/DD/YY")

Row7.Date7.rawValue = Num2Date(dayNum+6,"MM/DD/YY")

Row8.Date8.rawValue = Num2Date(dayNum+7,"MM/DD/YY")

Row9.Date9.rawValue = Num2Date(dayNum+8,"MM/DD/YY")

Row10.Date10.rawValue = Num2Date(dayNum+9,"MM/DD/YY")

Row11.Date11.rawValue = Num2Date(dayNum+10,"MM/DD/YY")

Row12.Date12.rawValue = Num2Date(dayNum+11,"MM/DD/YY")

Row13.Date13.rawValue = Num2Date(dayNum+12,"MM/DD/YY")

Row14.Date14.rawValue = Num2Date(dayNum+13,"MM/DD/YY")

Row15.Date15.rawValue = Num2Date(dayNum+14,"MM/DD/YY")

Row16.Date16.rawValue = Num2Date(dayNum+15,"MM/DD/YY")

Row17.Date17.rawValue = Num2Date(dayNum+16,"MM/DD/YY")

Row18.Date18.rawValue = Num2Date(dayNum+17,"MM/DD/YY")

Row19.Date19.rawValue = Num2Date(dayNum+18,"MM/DD/YY")

Row20.Date20.rawValue = Num2Date(dayNum+19,"MM/DD/YY")

Row21.Date21.rawValue = Num2Date(dayNum+20,"MM/DD/YY")

Row22.Date22.rawValue = Num2Date(dayNum+21,"MM/DD/YY")

Row23.Date23.rawValue = Num2Date(dayNum+22,"MM/DD/YY")

Row24.Date24.rawValue = Num2Date(dayNum+23,"MM/DD/YY")

Row25.Date25.rawValue = Num2Date(dayNum+24,"MM/DD/YY")

Row26.Date26.rawValue = Num2Date(dayNum+25,"MM/DD/YY")

Row27.Date27.rawValue = Num2Date(dayNum+26,"MM/DD/YY")

Row28.Date28.rawValue = Num2Date(dayNum+27,"MM/DD/YY")

Row29.Date29.rawValue = Num2Date(dayNum+28,"MM/DD/YY")

Row30.Date30.rawValue = Num2Date(dayNum+29,"MM/DD/YY")

Row31.Date31.rawValue = Num2Date(dayNum+30,"MM/DD/YY")

Row1.Day1.rawValue = Num2Date(dayNum,"EEE")

Row2.Day2.rawValue = Num2Date(dayNum+1,"EEE")

Row3.Day3.rawValue = Num2Date(dayNum+2,"EEE")

Row4.Day4.rawValue = Num2Date(dayNum+3,"EEE")

Row5.Day5.rawValue = Num2Date(dayNum+4,"EEE")

Row6.Day6.rawValue = Num2Date(dayNum+5,"EEE")

Row7.Day7.rawValue = Num2Date(dayNum+6,"EEE")

Row8.Day8.rawValue = Num2Date(dayNum+7,"EEE")

Row9.Day9.rawValue = Num2Date(dayNum+8,"EEE")

Row10.Day10.rawValue = Num2Date(dayNum+9,"EEE")

Row11.Day11.rawValue = Num2Date(dayNum+10,"EEE")

Row12.Day12.rawValue = Num2Date(dayNum+11,"EEE")

Row13.Day13.rawValue = Num2Date(dayNum+12,"EEE")

Row14.Day14.rawValue = Num2Date(dayNum+13,"EEE")

Row15.Day15.rawValue = Num2Date(dayNum+14,"EEE")

Row16.Day16.rawValue = Num2Date(dayNum+15,"EEE")

Row17.Day17.rawValue = Num2Date(dayNum+16,"EEE")

Row18.Day18.rawValue = Num2Date(dayNum+17,"EEE")

Row19.Day19.rawValue = Num2Date(dayNum+18,"EEE")

Row20.Day20.rawValue = Num2Date(dayNum+19,"EEE")

Row21.Day21.rawValue = Num2Date(dayNum+20,"EEE")

Row22.Day22.rawValue = Num2Date(dayNum+21,"EEE")

Row23.Day23.rawValue = Num2Date(dayNum+22,"EEE")

Row24.Day24.rawValue = Num2Date(dayNum+23,"EEE")

Row25.Day25.rawValue = Num2Date(dayNum+24,"EEE")

Row26.Day26.rawValue = Num2Date(dayNum+25,"EEE")

Row27.Day27.rawValue = Num2Date(dayNum+26,"EEE")

Row28.Day28.rawValue = Num2Date(dayNum+27,"EEE")

Row29.Day29.rawValue = Num2Date(dayNum+28,"EEE")

Row30.Day30.rawValue = Num2Date(dayNum+29,"EEE")

Row31.Day31.rawValue = Num2Date(dayNum+30,"EEE")

It still adds the beginning date for the following month if the month selected only has 30 days.  

I am not sure how to attach the file here for you to see.

Tracy

Avatar

Level 10

Hi,

your solution seems to be complicated, as you need to write a script for every single row.

I made an example for you that uses a dynamic table.

https://acrobat.com/#d=192ZhzEbnF9o9yx7ixE*Hw

Avatar

Level 2

There are 17 fields on each row that need scripting for time worked and leave taken.  It is quite a complicated two page form that is required to be in a specific format.  Could I email the form so you may have a look?

Tracy

Avatar

Level 10

Upload the form to Acrobat.com and share the link here.

Avatar

Level 2

Thank you so much.  This is the most difficult form I have ever done.

Tracy

https://acrobat.com/#d=MkIVhWQNjAX0Mha-LZGZKg

Avatar

Level 10

Hi,

please check that you shared the form, I got no access.

Avatar

Level 2

Try this.  I am new to the forums.  I apologize for my inexperience. I did not publish the form first.

Thank You!

https://acrobat.com/#d=MkIVhWQNjAX0Mha-LZGZKg

Avatar

Correct answer by
Level 10

Ok,

here's a modifiedversion of your form.

It uses a dynamic table, which has sevaral benefits like very slim calculation scripts and a small file size.

https://acrobat.com/#d=gTlaptez8XA2A5*0it4Wow

Avatar

Level 2

It is exactly what I need.   Now I know how ro accomplish this.   Thank you so much!  You are the BEST!!!

Tracy

Avatar

Level 2

I have one more question.  

I have reader enabled the form.   Upon a user completeing the form, none of the information input by the user into the time table will save.  The header information is saved and all page 2 information is saved, but nothing will save in table1.

Any suggestions?

Tracy

Avatar

Level 1

I need it for a month Employee name, log in time for arrival and depart, time log for lunch Time for daily activity log in and out, comments  and log time for Vacation, sick leave, personal leave holiday