Expand my Community achievements bar.

SOLVED

Date Calculation for Timesheet

Avatar

Level 1

I have been researching this for hours and I just can't figure it out so hopefully someone can help me here...

I have a timesheet form where I'd like the user to click on the first box which I've set up as a date field so the little calendar pops open. Once they choose the date in that field (which I've named dtf[0]) I'd like the rest of the fields to automatically populate with the dates for the remainder of that week. I'd prefer the format to only show the month and day - no year is necessary.

Example: the user chooses August 15, so the first field will show 8/15 and the rest of the week will be populated with 8/16, 8/17, 8/18 etc.

From a previous thread written here last year, I found this code and tweaked it to apply to my field names:

form1.#subform[0].dtf[0]::exit - (FormCalc, client)

xfa.form.form1.#subform.Table2.Row1.dtf[1] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+1),"M/D");
xfa.form.form1.#subform.Table2.Row1.dtf[2] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+2),"M/D");
xfa.form.form1.#subform.Table2.Row1.dtf[3] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+3),"M/D");
xfa.form.form1.#subform.Table2.Row1.dtf[4] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+4),"M/D");
xfa.form.form1.#subform.Table2.Row1.dtf[5] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+5),"M/D");
xfa.form.form1.#subform.Table2.Row1.dtf[6] = Num2Date((Date2Num(xfa.form.form1.#subform.Table2.Row1.dtf[0].formattedValue,"M/D")+6),"M/D");

But I'm running into the same problem that the person who wrote the other thread did... The fields after my date field are being populated, but with 1/1, 1/2, 1/3 etc!

By the way, the first field (dtf[0]) is a date/time field while the other days of the week are just plain text fields. (Wasn't sure if they should all be date/time fields, perhaps?)

What am I doing wrong here? I don't know anything about JavaScript or FormCalc (clearly)! Thanks for any assistance you can provide...

1 Accepted Solution

Avatar

Correct answer by
Level 10

Check the attached sample..

I am writing the script in the FormCalc and Exit event of the control..

Check the display pattern also.

https://acrobat.com/#d=xH1H6-8fmYRxxQn2sZuIMA

Thanks

Srini

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Check the attached sample..

I am writing the script in the FormCalc and Exit event of the control..

Check the display pattern also.

https://acrobat.com/#d=xH1H6-8fmYRxxQn2sZuIMA

Thanks

Srini

Avatar

Level 1

Yay - the answer was emailed to me - thank you!!! Here's what worked:

Put this script in the scripting window…

Show: exit

Language: FormCalc

Run At: Client

form1.#subform[0].Table2.Row1.dtf[0]::exit - (FormCalc, client)

dtf[1].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+1,"YYYY-MM-DD");

dtf[2].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+2,"YYYY-MM-DD");

dtf[3].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+3,"YYYY-MM-DD");

dtf[4].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+4,"YYYY-MM-DD");

dtf[5].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+5,"YYYY-MM-DD");

dtf[6].rawValue = Num2Date(Date2num(dtf[0].rawValue,"YYYY-MM-DD")+6,"YYYY-MM-DD");

Set the fields to Date/Time fields and their Pattern to date{MM/DD}.

Thank you so much!!!

Avatar

Level 1

     I am new to LiveCycle and I am trying to calculate the date on a  timesheet also. I have followed the instructions posted here but I am unable to get the desired results.   I was able to download the sample form that was posted here, but I am still unable to create a 14 day pay period were the dates automatically populate after you select the beginning date.

If possible and if you wouldn't mind can you post or email me at rikwil33@yahoo.coma sample document that has 14 day date fields that I could copy and paste to my timesheet form.  Thank you