Expand my Community achievements bar.

Formatting date in Javascript

Avatar

Former Community Member

I have a function written in javascript that needs to format a date as MMDDYYYY with all zeros intact, the problem is the date might be populated via XML as 7/1/2010 and I am getting 712010 which my barcode reading process then gets confused by.  The function has to be done in JS for a number of reasons due to all the other things it is doing but trying to use the JS dateFormat method is not working.  I made a little progress getting the value as a date doing the follow

fieldString

= new String(fieldName.rawValue);

var val = new Date(fieldString);

but calling dateFormat(val , "MMDDYYYY") bombs.

The other problem is that if the value is filled in by a user, even though the patterning of the field is

Display : date{MM/DD/YYYY}

Edit: date{MMDDYYYY}|date{MM/DD/YYYY}

Vaidation: date{MMDDYYYY}

Data: date{MMDDYYYY}

Empty and zeros NOT allowed

when I retrieve the value I get 2010-07-01, obviously this does not match the patter I expected.  So I am really looking for a general method of passing in any type of date and getting it back as MMDDYYYY, in Javascript.

Thanks

1 Reply

Avatar

Level 2

Hi,

How about using "formattedValue" property rather than "rawValue"?