O'Reilly logo

Beginning InfoPath™ 2003 by F. Scott Barker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.1. Date Calculations

One of the tasks that come in handy with some InfoPath forms is working with dates. The user interface doesn't really provide you with the ability to work with dates, but with scripting or managed code (C#) you can do so.

An example of date manipulation is taking today's date and displaying what tomorrow's date will be, or next week's, next month's, and even a year from today. You can see the values displayed in a form in Figure 14-1.

Figure 14.1. Figure 14-1

14.1.1. Simple Date Calculations Using Script

In both cases of creating the InfoPath form for displaying dates, you will be creating the form itself and then manipulating the InfoPath object model using code either in a script or as managed code. When discussing the code that is created using scripting, the first task to perform is to store today's date in a variable, using the following line of code:

var date = new Date();
14.1.1.1. JScript Date Object

The JScript Date object has a number of methods that can be used for extracting parts of the specified date. If you use the Date object as shown in the preceding line of code, the current system date is returned and, in this case, stored in the date variable.

Some of the methods that will be used for this section are shown in the following table:

MethodDescription
getDateRetrieves the current numeric day of the month of the Date object.
GetFullMonth ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required