Help Center

CPowerTime.DateDiffmethod

Returns the difference between two dates in years, months and days.

DateTimemethoddocumented

Syntax

SUB DateDiff (BYREF cpt AS CPowerTime, BYREF nSign AS LONG, BYREF nYears AS LONG, BYREF nMonths AS LONG, BYREF nDays AS LONG)

Parameters

NameDescription
cptIN. The PowerTime object to compare.
nSignOUT. Indicates that the internal value is smaller(-1), equal(0) or larger (+1).
YearsOUT. The years of difference between the two dates.
MonthsOUT. The months of difference between the two dates.
DaysOUT. The days of difference between the two dates.

Description

Returns the difference between two dates in years, months and days.

Remarks

The date part of the internal PowerTime object is compared to the date part of the specified external PowerTime object. The time-of-day part of each is ignored. The difference is assigned to the parameter variables you provide. nSign is -1 if the internal value is smaller. nSign is 0 if the values are equal. nSign is +1 if the internal value is larger. The other parameters tell the difference as positive integer values. If parameters are invalid, GetLastError will return ERROR_INVALID_PARAMETER.

Example

DIM cpt1 AS CPowerTime DIM cpt2 AS CPowerTime cpt1.NewDate(2019, 2, 2) cpt2.NewDate(1930, 12, 25) DIM AS LONG nSign, nYears, nMonths, nDays cpt1.DateDiff(cpt2, nSign, nYears, nMonths, nDays) print nSign, nYears, nMonths, nDays ' Output: 1, 88, 1, 8 ' 88 years, 1 month, 8 days

Reference

  • Defined in AfxNova/CPowerTime.inc:722
  • Documented in DateTime/CPowerTime Class.md
  • Topic: CPowerTime Class