Highlighted

Adobe LiveCycle Designer 8 - Add days to Current Date in another text field

Avatar

16-10-2008

Hi-

I am working on an expense report. I have six fields, CurrentDate, and countDate1 through countDate5. The CurrentDate is a Time/Date field which the user can select whatever date is needed with the drop down calendar. The other five countDate fields are "text" fields which will represent Monday through Friday. I would like to add zero days to whatever the user selects as the CurrentDate and make that appear in countDate1 which represents Monday(the CurrentDate the user selects will always be a Monday), add one day to whatever the user selects as the CurrentDate and make that appear in countDate2 which represents Tuesday...and so on. I realize this is probably basic for someone familiar with FormCalc but I'm very new at this.



This got me very close but I want the user to select the date and not have the CurrentDate already filled in.



CurrentDate - DateTime field, FormCalc calculation script:

num2date(Date())



Date1 - Text field, FormCalc calculation script:

Num2Date( Date2Num(CurrentDate.formattedValue))



Date2 - Text field, FormCalc calculation script:

Num2Date( Date2Num(CurrentDate.formattedValue) + 1 )



Thanks!

Brian

Replies

Highlighted

Avatar

Avatar

gkaiseril

Avatar

gkaiseril

gkaiseril

17-10-2008

You may need to provide the optional "format" value for the various date fields to get this to work.



CurrentDate - DateTime field, FormCalc calculation script:

num2date(Date(), "MMM DD, YYYY")



Date1 - Text field, FormCalc calculation script:

Num2Date( Date2Num(CurrentDate.formattedValue, "MMM DD, YYYY"), "MMM DD, YYYY")



Date2 - Text field, FormCalc calculation script:

Num2Date( Date2Num(CurrentDate.formattedValue, "MMM DD, YYYY") + 1, "MMM DD, YYYY")



Your date fields should also be a text field as the scrips are establishing the formatting of the data.



The date and time functions are dealing with a formatted string that is either being converted to a number or a number being converted to a formatted field and the script need to know the exact format for converting this data.
Highlighted

Avatar

21-10-2008

Geo,

Thanks for your help! With the above script you gave me it is working. However, are you referring to the "CurrentDate" Date/Time field being a text field as opposed to the Date/Time field which allows the user to select a date from the calendar because of formatting issues. As of now I have it as a Date/Time field but it automatically populates with the current date. You must click on the calendar to edit it. When you do click on the calendar and select a new date it asks "Are you sure you want to edit this field".



Also, when you do edit the calendar, if you go backwards more than one week it incorrectly calculates the other Date1 through Date5 text fields by starting at Jan. 01 1900. You can go forward as much as you like and there is no problem with that.
Highlighted

Avatar

21-11-2008

I am trying to do something close to this and I have tried un-succesfully to use the script you wrote.

My problem is I have a Date Field (Picker) that picks a date in the future. I need to include on my form several fields that automatically displays dates that are in the future at various intervals like 6 mo. - 5 mo. - 2 mo. - 14 days - 7 days out from the original date selected.



I tried to use both date and text field types but I have yet to get it to work.



Any Help ( I'm a New-B ) would be appreciated.
Highlighted

Avatar

Avatar

gkaiseril

Avatar

gkaiseril

gkaiseril

21-11-2008

Here is an exmaple of adding days the script is used in the "exit" event for the date select field that has display format of "MM/DD/YYYY". Adding days requires add x number of days to the days since the epoch date for the current date, adding months or years one needs to manipulate the string parts of the date.



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



// fomatted string for selected date

var sFmtDateValue = $.formattedValue

var sMsg = Concat("Entered date formatted: ", sFmtDateValue) // build message string

sMsg = Concat(sMsg, "\u000a" ) // add new line to message

// convert date string to days since epoch date - format is important

var fDaysPast = Date2Num(sFmtDateValue, "MM/DD/YYYY")

// add 7 days to days past epoch date

var f7DaysPlus = fDaysPast + 7 // add 7 days

var s7DaysPlus = Num2Date(f7DaysPlus, "MMM DD, YYYY") // format string for 7 days plus

sMsg = Concat(sMsg, "\u000a", "Plus 7 Days: ", s7DaysPlus) // build message string

// add 14 days to days past epoch date

var f14DaysPlus = fDaysPast + 14 // add 7 days

var s14DaysPlus = Num2Date(f14DaysPlus, "MMMM DD, YYYY") // format string for 7 days plus

sMsg = Concat(sMsg, "\u000a", "Plus 14 Days: ", s14DaysPlus) // build message string

// display results



// work on months

// get parts of date past epoch date

var sFullYear = Num2Date(fDaysPast, "YYYY") // get 4 digit year form days past epoch date

var sMonth = Num2Date(fDaysPast, "MM") // get month form days past epoch date as number

var sDate = Num2Date(fDaysPast, "DD") // get date form days past epoch date as a number



var s2Month = Sum(sMonth, 2) // add 2 months

var s2FullYear = sFullYear

// if more than 12 months in new date adjust year on number of months

if (s2Month > "12") then

s2FullYear = Sum(s2FullYear, + 1) // increment year

s2Month = Sum(s2Month, - 12) // adjsut months

endif

var s2MonthsAdded = Concat(s2Month, "/", sDate, "/", s2FullYear) // date string

sMsg = Concat(sMsg, "\u000a", "Added 2 months: ", s2MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);



var s5Month = Sum(sMonth, 5) // add 5 months

var s5FullYear = sFullYear

// if more than 12 months in new date adjust year on number of months

if (s5Month > "12") then

s5FullYear = Sum(s5FullYear, + 1) // increment year

s5Month = Sum(s5Month, - 12) // adjsut months

endif

var s5MonthsAdded = Concat(s5Month, "/", sDate, "/", s5FullYear) //build Date string

sMsg = Concat(sMsg, "\u000a", "Added 5 months: ", s5MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);



// display results

xfa.host.messageBox(sMsg, "Sample Adding Days and Months" ,3, 0);
Highlighted

Avatar

24-11-2008

Geo,



Is it possible to email a sample 3 line 3 field pdf form to you or anyone that can help.



Unfortunately for me this is the first time for me using LiveCycle Designer. I think I have a handle on most of it but writing scripts is currently beyond my capability. I have created a simple three line pdf file that contains 3 fields. The first field is a date picker that the user chooses a FUTURE DATE. The other two fields I want to be automatically filled in depending on the future date selected in the first field. The other two fields should calculate dates BEFORE the date selected.



What I am trying to set up is when a FUTURE DATE (which can change) is selected using the date picker the other FIELDS displays time periods BEFORE the FUTURE DATE as (earliest DATE to START) and ( the last possible DATE to FINISH)



This is part of a TO DO LIST with a SET TIME for completion of the project.



Example:



BY JULY 10, 2009 (DUE DATE) Items A thru D must be completed between February 10, 2009 and March 10, 2010 (6 MONTHS to 5 MONTHS prior to DUE DATE.



Items E thru J must be completed between March 10, 2009 and April 10, 2010 (5 MONTHS to 4 MONTHS prior to DUE DATE.



Items K thru N must be completed between April 10, 2009 and May 10, 2010 (4 MONTHS to 3 MONTHS prior to DUE DATE.



And so on until finally a date no later than one week prior to the DUE DATE.



Thanks for your time and consideration
Highlighted

Avatar

08-01-2009

I have a similar problem. I have a DateTimeField3 which has a date to be entered. In DateTimeField4 I want it to calculate the date plus 280 days. I am at a loss on how to do this. I have tried to put the script $ = num2date(DateTimeField+280) in the DateTimeField4 but get no results.



Can you help?



Thanks
Highlighted

Avatar

25-02-2009

I'm in the same boat as Allan. I'm trying to add 14 to the current date. Nothing seems to work. Any ideas? Thanks.
Highlighted

Avatar

Avatar

gkaiseril

Avatar

gkaiseril

gkaiseril

26-02-2009

Because formatted date strings are language dependent, you should specify the optional formatted date string pattern.



With a field named "MyDate" and a formatted value of "MMM DD, YYYY", the script to add 14 days in FormCalc is:



if(HasValue(MyDate)) then

Num2Date( (Date2Num(MyDate.formattedValue, "MMM DD, YYYY") + 14), "MMM DD, YYYY")

else

null

endif



You may also want to add a validation format to ensure that the inputted date is acceptable.
Highlighted

Avatar

Avatar

ech0

Avatar

ech0

ech0

10-03-2009

HI Geo,

doing someting very similar as above- have changed the object names but i'm still getting an error



here is the snippett:

if(HasValue(sundaystartdate.formattedValue,"mmm d, yyyy"))then

MondayDate((Date2Num(sundaystartdate.formattedValue,"mmm d, yyyy")+1),"mmm d, yyyy")

else

null

endif



here is the error i'm getting: function 'MondayDate' on line....is unknown'



is this a simple syntax error or did i miss a bigger piece somewhere?



thanks- from a complete noob....

eric