Date Addinterval number date

This function returns a date that corresponds to a date plus some interval. The interval variable is a time unit (days, hours, weeks, and so on), number is the number of intervals to be added to the initial date, and date is the initial date. If number is positive, the date returned by DateAdd() is in the future. If it's negative, the date returned is in the past. The interval argument can take one of the values in

Table 17.

Table 17: The DateInterval Enumeration

Value

Year Quarter Month DayOfYear

Continued on next page

Table 17: The DateInterval Enumeration (continued)

Value

WeekDay

WeekOfYear

Hour

Minute

Second

To find out the date one month after December 31, 2002, use the following statement: Conso1e.WriteLine(DateAdd(DateInterva1.Month, 1, #12/31/2002#)) The result is:

1/31/2003 12:00:00 AM

The DateAdd() function is similar to the DateSerial() function (described earlier), but it takes into consideration the actual duration of a month. For DateSerial(), each month has 30 days. The following statements:

Conso1e.WriteLine(DateSeria1(year(day1), month(day1) + 1, day(day1))) result in: 3/2/02

which is a date in March, not February.

0 0

Post a comment