Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / August 2007

Tip: Looking for answers? Try searching our database.

Calculated Date Format in InfoPath 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bobby - 01 Aug 2007 00:38 GMT
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);

}
David Dean - 01 Aug 2007 02:56 GMT
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.

Signature

David Dean
Sr. Member Technical Staff
Insource Technology Corp.

> 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
[quoted text clipped - 33 lines]
>
> }
Bobby - 01 Aug 2007 19:30 GMT
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.

> 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.
[quoted text clipped - 44 lines]
> >
> > }
Bobby - 01 Aug 2007 19:52 GMT
Ok, now I feel stupid, I was not using an expression box.  I was using a text
box control.  Thanks for the help.

> 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.
[quoted text clipped - 44 lines]
> >
> > }
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.