Calculated Date Format in InfoPath 2003

B

Bobby

I am using the following script to calculate a new date in InfoPath 2003,
however, the output date format is in yyyy-mm-dd instead of the mm/dd/yyyy I
started with and need it to be. Changing the properties of the output field
to anything but "text(string)" prevents the script from running. What am I
doing wrong? How do I change the dateObj format back from yyyy-mm-dd?
Thanks.

function GetDateString(dateObj)
{
var yyyy = dateObj.getFullYear();
var mm = dateObj.getMonth() + 1;
var dd = dateObj.getDate();

if (mm < 10)
mm = "0" + mm;

if (dd < 10)
dd = "0" + dd;

return yyyy + "-" + mm + "-" + dd;

}

function msoxd_my_ReferralDate::OnAfterChange(eventObj)
{
if (eventObj.IsUndoRedo)
return;

var dateObj = new
Date(eventObj.Site.text.replace(/(\d\d\d\d)-(\d\d)-(\d\d)/, "$2-$3-$1"));
var dateVal = dateObj.getDate();

dateObj.setDate(dateVal + 45);
XDocument.DOM.selectSingleNode("my:IFSP/my:FourtyFifthDay").text =
GetDateString(dateObj);

}
 
D

David Dean

If the element you are trying to set has a schema datatype of "date", then
the value must be in the YYYY-MM-DD format based on the ISO 8601 standard.
Likewise, a "dateTime" field would be stored in YYYY-MM-DDTHH:MM:SS format.

You control how a date field is formatted for display by setting the Format
for the text box or expression box used to show the date. When a valid date
is entered in m/d/yyyy format, InfoPath parses the text box entry and saves
it into the field in YYYY-MM-DD format; however, it will display it on the
form using whatever format you select in the Properties dialog for the
control.
 
B

Bobby

When I change the formatting for the text box it changes for the control as
well. At that point I get nil errors in the script.
 
B

Bobby

Ok, now I feel stupid, I was not using an expression box. I was using a text
box control. Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top