DiffMonths

Use this function to determine the number of months difference between two dates and return that value.

Syntax

DiffMonths (Date1, Format1, Date2, Format2)

Parameter

Description

Date1

Enter a date string. The system assumes this date string is in the format specified by the Format1 parameter. The default is the current date.

Format1

Enter a date format string that describes the Date1 parameter. The default is date format 1 (MM/DD?YY).

Date2

Enter a date string. The system assumes this date string is in the format specified by the Format2 parameter. The default is the current date.

Format2

Enter a date format string that describes the Date2 parameter. The default is date format 1.

The system calculates the number of complete months between given dates. For example, from 2/10 to 3/10 is considered one month, and from 2/10 to 3/15 is also considered one month.

The system always returns a positive number regardless of which date string parameter is later in time. The result is always given in number of months regardless of the number of years included.

Example

Here are some examples:

(Assume the current date is 07/01/95.)

Function

Result

Explanation

DiffMonths ("7/15/95")

0

The second parameter defaults to the current date. Since the value does not equal an entire month the result is 0.

DiffMonths ("05/01/95", "1")

2

The second parameter defaults to the current date.

DiffMonths ("October 31, 1961", "4", "10/31/95", "1")

408

Note that the result includes several years worth of months. In addition, two different date formats are used.

See also