These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Set Date 1 Year From Picked Date

aehare70
Registered: Dec 11 2007
Posts: 12
Answered

I have a START Date and an END Date. I am allowing the user to pick the START Date, but would like to make the END Date a static date of 1 year after based on the START Date.

Example:

START Date: 01/01/2000 (picked with calendar by user)
END Date: 01/01/2001 (auto-calculated and static based on START Date picked)

Can anyone help?

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You can write a JavaScirpt calculation for the "END" date.

// convert date string to a date time objectvar oDate = util.scand("mm/dd/yyyy", START.formattedValue);// extract the full yearvar sFullYear = oDate.getFullYear();// extract zero based monthvar sMonth = oDate.getMonth();// extract datevar sDate = oDate.getDate();// create formatted display string from month, date, and  year plus 1 year$.formattedvalue = util.printd("mm/dd/yyyy", new Date((sFullYear + 1), sMonth, sDate) );

Since dates are a specially formatted strings that are converted to a number or object, the use of the format picture is very important. If it is not correct the conversion and the code will not work.

George Kaiser

aehare70
Registered: Dec 11 2007
Posts: 12
gkaiseril wrote:
// convert date string to a date time objectvar oDate = util.scand("mm/dd/yyyy", START.formattedValue);// extract the full yearvar sFullYear = oDate.getFullYear();// extract zero based monthvar sMonth = oDate.getMonth();// extract datevar sDate = oDate.getDate();// create formatted display string from month, date, and  year plus 1 year$.formattedvalue = util.printd("mm/dd/yyyy", new Date((sFullYear + 1), sMonth, sDate) );
Would I place this in the initilize event of the end date?
i.e. event name:
topmostSubform.Body_Page1.BasicInformation.aer_ExceptionDurationScheduleEndDate::initialize - (JavaScript, client)

gkaiseril wrote:
the use of the format picture is very important. If it is not correct the conversion and the code will not work.
Can you explain what this is?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You need to use this for the "Calculation" event so the calculation will be performed when the "START" field is changed to a new date. You will also need to indicate that the calculation is using "JavaScript" and not "FormCalc".

The date string consist of 4 parts, the date of the month, the month (as a number or character string), the year (either as a 2 digit or 4 digit number) and a separator. Different countries arrange these items in different orders or organiztions may have a different standard than the numeirc string, you need to provide the required arrangement string for the conversion to properly occur. For example, January 31, 2000 can be:

01/31/2000
1/31/00
2000-01-31
1 Jan 2000
1 January 2000

George Kaiser

aehare70
Registered: Dec 11 2007
Posts: 12
Thanks! Works great!
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
There is also a way for this calculation in FormCalc that is quite easier.

Calculates end date every time the calculate event is fired.
Form1.Page1.END::calculate - (FormCalc, client) Num2Date(Date2Num(Form1.Page1.START.formattedValue, DateFmt(2))  + 365, DateFmt(2))

Calculates end date only if there is no end date until now.
Form1.Page1.END::calculate - (FormCalc, client) if (Form1.Page1.START.rawValue==null)then$.rawValue = ""elseNum2Date(Date2Num(Form1.Page1.START.formattedValue, DateFmt(2))  + 365, DateFmt(2))endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Assuming a year only has 365 days. Since there is a fractional day involved. Because February in a leap year will have 29 days this assumption can create a material error. Try any date in 2008 prior to March 1, 2008 for an example. You computation will give the result for 365 days but not one year.

If FormCalc one could use:
----- form1.#subform[0].END[1]::calculate: - (FormCalc, client) ------------------------------------ if (HasValue(START) )thenvar fDays = Date2Num(START.formattedValue, DateFmt(2))var fYear = Num2Date(fDays, "YYYY")var fMonth = Num2Date(fDays, "MMM")var fDate = Num2Date(fDays, "DD")var fPlusYear = Sum(fYear, 1)Concat(fMonth, " ", fDate, ", ", fPlusYear)elsenullendif

George Kaiser

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Oh George, you're right at this point, didn't think of it. Ups!

I normally use this script only for adding a specific number of days, then it's perfect.
:rolleyes:

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs