You are here: Function Reference > Alphabetical Listing > D > DiffYears

DiffYears

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

Syntax

DiffYears (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 years between the given dates. For example, from 2/10/08 to 2/10/09 is considered one year, while 3/1/08 to 2/29/09 is considered zero years.

The system always returns a positive number, regardless of which date string parameter occurs later.

Note When calculating leap years, February 28th and 29th are considered equal, since both represent the last day of February. For example, February 29, 2008 to February 28, 2009, is considered one year.

Example

Here are some examples (assume the current date is 07/01/09):

01/31/2008 to 01/30/2009 = zero years difference (it will not be a year until 01/31/2009 as the year 2008 is a leap year)

Function

Result

Explanation

DiffYears ("7/15/09")

0

The second parameter defaults to the current date. Since the value is not an entire year, the result is zero (0).

DiffYears ("01/31/2009", "4", "01/30/2009", "1")

0

The result will not become one (1) until January 31, 2009.

DiffYears

("01/010/05", "1")

4

The second parameter defaults to the current date.

DiffYears ("October 31, 1975", "4", "10/31/09", "1")

34

Note that the result includes numerous years. In addition, two different date formats are used.

See also