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:
Method | Description |
---|---|
getDate | Retrieves the current numeric day of the month of the Date object. |
GetFullMonth ... |
Get Beginning InfoPath™ 2003 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.