Date Validation/Calculation

J

Jamie Durrant

I've seen this question pop up time and time again. How do we calculate dates
within Infopath. All I want to do is work out how many days between two
dates. Searched everywhere but the only response I have ever seen is : "Check
the Infopath SDK on data validation."

Could you be a little more specific ? I've checked the SDK and samples, but
haven't come across any DATE (not data) calculation.

Many thanks,

Jamie.
 
J

Jamie Durrant

Nope, sorry.. Doesn't seem like anyone can give me an answer on this problem.
I just had to ignore that part of the form. Shame though, as it would have
been really useful.
 
M

Matthew Blain \(Serriform\)

One way to handle dates is with script.

The Events sample (I believe this is part of the SDK) has code which does
this.

Dates in InfoPath are in ISO 8601 format -- YYYY-MM-DD or some such (I don't
have it off the top of my head). JScript doesn't understand this format, but
you can do string manipulation to turn it into MM/DD/YYYY and then call new
Date(yourstring) and do any sort of calculation you want, then when you're
done convert it back into ISO format.

You can use the date formatting code in the .NET framework even easier than
with script.

--Matthew Blain
http://www.developingsolutionswithinfopath.com
http://www.microsoft.com/mspress/books/7128.asp
 
J

Jamie Durrant

Hello,

Could you tell me which SDK sample has this example, as I've looked and
looked and could only find Data Manipulation.

Thank you,

Jamie
 
K

Kevin

In managed code (c#) this is a pretty simple calculation. I pilfered this
off the web from someone (even does weekdays!):

public int CountWeekdays(DateTime startTime, DateTime endTime)
{
TimeSpan ts = endTime - startTime;
Console.WriteLine( ts.Days );
int cnt = 0;
for (int i=0; i<ts.Days; i++)
{
DateTime dt = startTime.AddDays(i);
if (IsWeekDay(dt))
{
cnt++;
}
}

return cnt;
}
 

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