Expand my Community achievements bar.

**PLEASE HELP**Need Help adding date ranges to form

Avatar

Former Community Member
I have designed a form with approximately 28 user defined date fields. I want the user to be able put in the first date range and then seautomaticaly fill in the other dates sequencially.



ie,.... the user puts in 08/01/2007 then the following date field populates with 08/02/2007, then 08/03/2007 and so on....
6 Replies

Avatar

Level 7
Have a look at the "Date2Num()" and the "Num2Date" FormCalc functions.



The "Date2Num()" function takes a formatted date and returns the number of days from the epoch date, Jan 1, 1900, and the "Num2Date()" function takes the number of days since the epoch date and returns the formatted date string. So one could get the number of days from the epoch date for a given date and add 1 day, and then convert the revised number of day back to a formatted date.

Avatar

Former Community Member
COuld you give me an example....I'm not that good.

Avatar

Level 7
The following script can be used for the "exit" action so the basic action to get the start date's number and then it can be used to compute the next days field values by adding the appropriate number of days. A more experienced user could use a control loop t0 modify the field names and number of days to add to the start date's day number for the additional date fields.



// Script for exit from date select field

// perform calculation only if an input date has been selected

if (HasValue(cInputDate)) then

// format string for the date fields

var cDateFormat = "MMM D, YYYY"



// intermediate information start - optional

xfa.host.messageBox(Concat("The input date formatted value is: ", cInputDate.formattedValue, "

The input date's numeric value: ", Date2Num($.formattedValue, cDateFormat), "

The adjusted date number is: ", (Date2Num($.formattedValue, cDateFormat) + 1), "

The adjusted date is: ", Num2Date(Date2Num($.formattedValue, cDateFormat) + 1) ),

"Intermediate Detail", 3, 0)

// intermediate information end - optional

var StartDateNumber = Date2Num($.formattedValue, cDateFormat)

// add 1 day to StartDateNumber

cAdjustDate = Num2Date(StartDateNumber + 1, cDateFormat)

// add code for additional date fields here adding appropriate number of days for date

else

cAdjustDate = "" // no input keep field blank

// add code for additional date fields here

endif

Avatar

Former Community Member
I figured out that I could do basically the same thing by putting this simply calculate forumula in each field:



Num2Date(IsoDate2Num(form1.#subform[0].#subform[1].#subform[3].#field[1])+1)



,but I can't figure out how to keep the fields blank until the original date is inputed by the user. In other words, the calculated fields all show Jan 1, 1900 until the base date is changed by the user.



How can I hide the Jan 1, 1900 date until the base date is inputed?

Avatar

Level 7
Look at the "HasValue()" function and use it in a logical comparison.



if (HasValue(form1.#subform[0].#subform[1].#subform[3].#field[1]) ) then

// if date field has a non-blank value then compute date

Num2Date(IsoDate2Num(form1.#subform[0].#subform[1].#subform[3].#field[1])+1)

else

// force to blank if no value entered

""

endif

Avatar

Former Community Member
Thanks alot, you have been most helpful....I owe you one dude!!!!!!