8.4.12 GetDateCount (calculate the difference between dates)
- Purpose
-
Calculates the difference between two specified dates.
- Syntax
GetDateCount (StartDate, EndDate [, UnitofDate])
- Arguments
-
- StartDate
-
Write the date from which to start the count in yyyy/mm/dd format. Numbers specified in the range 0 to 69 in yyyy are read as 2000 to 2069.
If an invalid value is specified for mm, an error occurs. However, if an invalid value is specified for dd, no error occurs. Instead, the GetDateCount command replaces the specified date with the equivalent valid date and returns the result.
For example, if 1999/12/33 (a nonexistent date) were specified, the GetDateCount command would replace the specified date with the valid date 2000/01/02.
- EndDate
-
Write the date at which to end the count in yyyy/mm/dd format. Numbers specified in the range 0 to 69 in yyyy are read as 2000 to 2069. If an invalid value is specified for mm, an error occurs. However, if an invalid value is specified for dd, the GetDateCount command replaces the specified date with the equivalent valid date.
- UnitofDate
-
Specify the units in which to calculate the elapsed time as one of the following values:
Value
Meaning
YearU
Get the number of elapsed years.
For example, if the start date is 1998/4/1 and the end date is 1999/4/1, the calculation result will be 1. If the end date is 1999/3/1, the calculation result will be 0.
MonthU
Get the number of elapsed months.
For example, if the start date is 1998/4/10 and the end date is 1998/5/10, the calculation result will be 1. If the end date is 1998/5/9, the calculation result will be 0.
DayU
Get the number of elapsed days.
This value is optional. If you omit this value, DayU is assumed.
- Description
-
The GetDateCount command calculates the difference between two specified dates, and returns the elapsed time as the command execution result. If the date specified in StartDate is later than the date specified in EndDate, a negative value is returned.
- Example
' Calculate the elapsed time from 1998/4/1 to 1999/3/31 ' in years, months, and days. Dim date1, date2, yBuff, mBuff, dBuff date1 = "1998/4/1" date2 = "1999/3/31" ' The following code stores 0 in yBuff, 11 in mBuff, ' and 364 in dBuff. yBuff = GetDateCount (date1, date2, YearU) mBuff = GetDateCount (date1, date2, MonthU) dBuff = GetDateCount (date1, date2, DayU)
- JP1/Script version
-
Supported from JP1/Script 05-20.