Expand my Community achievements bar.

SOLVED

Dynamic dates question

Avatar

Level 1

Hello, and thank you taking a moment to look at my issue.

I have attempted to search for a solution but have not found one that I understand.

Our pay periods vary in length and are never a fixed number of days. I want to have two date fields at the beginning of the time sheet that define the start date, and the end date of the pay period.

Below this I will have twenty text or date cells (whichever will work) that I want to auto populate with the range of dates defined in the FROM_DATE, and the TO_DATE fields.

The first cell date should equal the FROM_DATE date, and the ending cell should be equal the TO_DATE fields value. with the cells in between auto populated sequentially.

The dates should not populate in the empty cells past the date defined in the TO_DATE field, yes there will be empty cells at the end of the form, and this is ok.

Thank you for your time.
Jason

1 Accepted Solution

Avatar

Correct answer by
Level 7

you only need to put the code in once,  in the exit event of To_Date.

You will need to name all the other fields Date01 for the loop to work.

View solution in original post

6 Replies

Avatar

Level 7

You use the Date2Num and the Num2Date functions to achieve this. So you would take your start date (say in a field called start) and turn it into a number like this:

var currentDate = Date2Num(start.formattedValue, "DD/MM/YYYY") //in whatever date format you used

then you add 1 to your number for the next day (currentDate = currentDate + 1) and turn it back into a date like this:

Num2Date(currentDate, "DD/MM/YYYY")

To autofill all your cells you would probably do a loop in the exit event of your end date which takes the first date and then does this looping until you get to your end date.

Avatar

Level 1

Thank you whyisthisme.

I am able to calculate the number of days, however the scripting skills are lacking with this one. I am currently looking for a good loop script example.

Thanks again,

Jason

Avatar

Level 7

OK so to start I have 2 date fields called start and end. These are where you enter the start and end dates for your pay period. For my example I have set the date format to DD/MM/YYYY so if you change this you will need to alter the code below accordingly.

Then to fill the actual dates I have made a table called dateTable and called every row Row1, and every cell in the column we are going to enter the dates Cell1. Each row will automatically be renamed with an index (so Row1[0], Row1[1], Row1[2], etc) and it is this index we will use in our loop.

Then in formcalc in the exit event of end (which is the last date in the pay cycle) I have put:

var startDate = Date2Num(start.formattedValue, "DD/MM/YYYY")

var endDate = Date2Num($.formattedValue,"DD/MM/YYYY")

var rowCount = 0

while (startDate <= endDate) do

        dateTable.Row1[rowCount].Cell1 = Num2Date(startDate, "DD/MM/YYYY")

        rowCount = rowCount + 1

        startDate = startDate + 1

endwhile

Avatar

Level 1

Whyitsme,

Thank you again. I am making progress (I think) however I am unable to create tables as LiveCycle crashes to the desktop everytime i try to use the table feature. (just my luck)

Below is the modified script, along with a screen shot of the PDF, and a link to the test PDF

Your help is truly appreciated. Thank you again.

Jason

http://dl.dropbox.com/u/24475924/Date_Calc_Test.pdf

PDF.png

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

var To_Date = Date2Num($.formattedValue,"MM/DD/YYYY")

var rowCount = 0

while (From_Date <= To_Date) do

        Date01[rowCount] = Num2Date(From_Date, "MM/DD/YYYY")

        rowCount = rowCount + 1

        From_Date = From_Date + 1

endwhile

Avatar

Correct answer by
Level 7

you only need to put the code in once,  in the exit event of To_Date.

You will need to name all the other fields Date01 for the loop to work.

Avatar

Level 1

Well I do not know how to thank you enough. Your help is appreciated very much. Now all I need to do is fix the validation error.

Again Many Thanking Ewe's

Jason