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 / September 2005

Tip: Looking for answers? Try searching our database.

Date Picker Calculation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tmons - 29 Sep 2005 17:58 GMT
I have two date picker fields - an Effective Date Start and an Effective Date
End.  I'd like the end date to automatically populate one year from the date
entered in the start date.  Can you give me the correct formula for this?
Franck Dauché - 29 Sep 2005 18:02 GMT
Hi,

Did you check:
http://blogs.msdn.com/infopath/search.aspx?q=date+calculation&p=1

Franck Dauché

> I have two date picker fields - an Effective Date Start and an Effective Date
> End.  I'd like the end date to automatically populate one year from the date
> entered in the start date.  Can you give me the correct formula for this?
tmons - 29 Sep 2005 18:07 GMT
I did.  However, I'm not a programmer and haven't a clue what I should do.

> Hi,
>
[quoted text clipped - 6 lines]
> > End.  I'd like the end date to automatically populate one year from the date
> > entered in the start date.  Can you give me the correct formula for this?
Franck Dauché - 29 Sep 2005 19:03 GMT
Hi,

Let's build a little project to get you started:

create new IP project (with C# behind) using Visual Studio.
Drop 2 date picker controls on your page (you now have 2 fields in your
schema: field1 and field2).
For the purpose of this exercise, open you mayschema.xsd file and go to the
XML view.
remove the "nillable=true" lines to give:
<xsd:element name="field1" type="xsd:date"/>
<xsd:element name="field2" type="xsd:date"/>

Next, at the bottom of your FormCode.cs code page, copy the 2 functions
given to you in the blog:
private static DateTime Iso8601ToDate( string iso8601Date )
{
    if( iso8601Date == null ) throw new ArgumentNullException( "iso8601Date" );
    return DateTime.ParseExact( iso8601Date, "yyyy-MM-dd", null );
}
private static string DateToIso8601( DateTime dateTime )
{return dateTime.ToString( "yyyy-MM-dd" );}

Then, go to your IP form:
Right-click on the first Date Picker (field1), click on Data Validation,
select OnAfterChange from the event drop-down and click Edit.
Now insert the following code:
[InfoPathEventHandler(MatchPath="/my:myFields/my:field1",
EventType=InfoPathEventType.OnAfterChange)]
public void field1_OnAfterChange(DataDOMEvent e)
{
    if (e.IsUndoRedo){return;}
    IXMLDOMNode dateNode = thisXDocument.DOM.selectSingleNode( "//my:field2" );
    try
    {
        DateTime dt = Iso8601ToDate( e.Source.text );
        dt = dt.AddYears( 1 );
        dateNode.text = DateToIso8601( dt );
    }
    catch( FormatException ) {}
}

run your form, pick 1 date in Date Picker 1, Date Picker 2 fills up with the
same date + 1 year...

Voila!

Hope that it helps you.

Franck Dauché

> I did.  However, I'm not a programmer and haven't a clue what I should do.
>
[quoted text clipped - 8 lines]
> > > End.  I'd like the end date to automatically populate one year from the date
> > > entered in the start date.  Can you give me the correct formula for this?
 
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.