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

Updating a Date Field

RAYD7024
Registered: Aug 5 2009
Posts: 13
Answered

How do I increment the date that is displayed in a date field using JavaScript? I've read Thom parker's "Working with date and time in Acrobat" and here is my feeble attempt:

var oneDay = 24 * 60 * 60 * 1000;
var strStart = xfa.resolveNode("DateStart").rawValue;
var dateStart = util.scand("yyyy-mm-dd",strStart);
var dueMillis = dateStart.getTime() + oneDay;
var newDate = new Date(dueMillis);

// This is where my problem lies.
xfa.resolveNode("Table1.Row1[" + nIndex + "].DATE").rawValue = newDate.rawValue;

The date field that I want to increment is DateStart. I'm stuck. Can someone please tell me what I'm doing wrong? Any and all help will be greatly appreciated.

My Product Information:
LiveCycle Designer, Windows
hcorbin
Registered: Aug 11 2009
Posts: 57
Hi,

I’ve noticed two things:

1. The nIndex variable isn’t defined in the snippet provided.
2. Don’t use the xfa property ‘rawValue’ to access the value of the variable newDate. All you need is

xfa.resolveNode("Table1.Row1[" + nIndex + "].DATE").rawValue = newDate;
Hope this helps,
Hélène
RAYD7024
Registered: Aug 5 2009
Posts: 13
Thanks.

That got me one step closer. Now I'm getting an "Adobe DATE validation failed" message. I used console.println to get a peek at newDate and here's what I saw:

Wed Aug 26 2009 00:00:00 GMT-0400 (Eastern Daylight Time)

The DATE field validation pattern is set to yyyy-mm-dd.

Any suggestions would be greatly appreciated?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It might be easier to use LiveCycle Designer's functions 'Date2Num()' and "Num2Date()'.

// get the start date string in a known formatvar strStart = DateStart.formattedValue;xfa.host.messageBox( Concat("Formatted date = ", strStart) );var dateStart = Date2Num(strStart, "YYYY-MM-DD");xfa.host.messageBox( Concat("Days since Epoch date = ", dateStart) );// increment date by one dayvar dueMillis = dateStart + 1;xfa.host.messageBox( Concat("Next day since Epoch date = ", dueMillis) );// format the new date stringvar newDate = Num2Date(dueMillis, "MM-DD-YYYY");xfa.host.messageBox( Concat("Next date = ", newDate) );

Thom Parker's date and time tutorials were writted for Acrobat's form JavaScript and not LiveCycle Designer's JavaScript.

George Kaiser

RAYD7024
Registered: Aug 5 2009
Posts: 13
Thanks for the input. Thea part of the script I've shown is only one part of a large script that is written in JavaScript. So, FormCalc is not an option at this point. I'll find a way to do it with javaScript eventually.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you want to stay in JavaScirpt you need to keep track of the date's character string, the date's JavaScript object and the date's value of the date JavaScript object.

console.show();console.clear();// establish some time constantsvar fSec = 1000; // 1000 milliseconds in on secondvar fMin =  fSec * 60; // 60 seconds in one minutevar fHr = fMin * 60; // 60 minutes in one hourvar fDay = fHr * 24; // 24 hours in one day// get the start date string in a known formatvar strStart = DateStart.formattedValue;// display the date stringconsole.println("Formatted date = " + strStart);// convert date string into a date objectvar dateStart = util.scand("yyyy-mm-dd", strStart);// display the date objectconsole.println("Date Object = " + dateStart);// display date object as a valueconsole.println("Milliseconds since Epoch date = " + dateStart.valueOf() );// increment date value by one dayvar dueMillis = dateStart.valueOf() +  fDay;// display millisecondsconsole.println("Milliseconds for next day: " + dueMillis);// convert milliseconds value into a date objectvar newDate = new Date(dueMillis);// display new date objectconsole.println("newDate object: " + newDate);// format the next day's date objectvar dueDate = util.printd("yyyy-mm-dd", newDate);// display the formatted date stringconsole.println("Next date formatted: " + dueDate);// additional code to place the string value

Much of this information comes from the example in the Acrobat JavaScirpt Guide.

George Kaiser