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

Date function - Problem with util.scand()

deepusrp
Registered: Jan 12 2009
Posts: 51

Hello All,

I have several date/time fields in my form on which i'm performing some date validations based on certain events.

I have a strange problem while performing validations. If user selects the date from the dropdown calendar for the fields, then the validations are working fine. But if the user manually enters the date, then validations are not working.

I'm using javascript for the validation and i'm using [b]util.scand()[/b] function inside the script.

i did some investigation on its behaviours, and some of the things are:

-> By default, date/time converts the selected date to 'YYYY-MM-DD' format ([b]Can I change this to other format?[/b]) . So i'am using

var Date1 = Form.PAGE2.DEAL.TermTo.rawValue;
var fromDate = util.scand("yyyy-mm-dd", Date1);

scand() will return a valid date.

-> If user enters a value on the fileld, eg: 'DD-MM-YYYY', the field is not converting to the usual format. And obviously scand() is retuning NULL as the date is not in the expected format.

I want to have both the selection of date as well as manual entry and i fix to a particular format, eg:'DD-MM-YYYY'.

Can I do that?

Thanks in advance

Deepak

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You have to be careful when mixing AcroForms JavaScript and LiveCycle Designer because of the differences between the supported properties, methods, and syntax. I have fond use of the 'formattedValue' provides the most reliable string for date conversions as it is the date with the defined format and not acceptable date formatted string.

Are you getting any errors in LiveCycle Designer or the JavaScript debugging console?

Why not use the date time functions of LiveCycle Designer?

The purpose of the 'util.scand()' function is to convert a date or time into JavaScirpts data time object which can be converted into the time from the Epoch date in milliseconds and it is not supported by LiveCycle Designer. Do you need the date expressed in milliseconds?

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The answer is to do one of two things.

1) use regular expressions, or other tests, to figure out which format you have and then perform the conversion.

2) Use "scand()" twice, once with each format and see which, if any, returns a valid value.

BTW: scand() is suppored in LiveCycle through the Acrobat JavaScript bridge. If you know the form is PDF then most of the Acrobat JavaScript DOM is availible.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

deepusrp
Registered: Jan 12 2009
Posts: 51
Hi,

Thanks for ur reply...

By any way, can i block the manual entry to the date/time field? so that the user is forced to use the dropdown calendar...

OR can i have a script which opens the calendar whenever a user enters the date/time field.

The main purpose of using scand() is to have date validations easier. If you convert the dates to a valid javascript date object, then you can use them in comparisons easily.

if (date1 > date2)
{
//do something.
}

I need to do date comarisons on my form like i showed above. If you have any better method (without using scand()), then please let me know. If possible provide me with a code snippet. That would be great.

Thanks once again for the kind reply

Deepak