| AddYrs Function |
Unit
QESBPCSDateTime
Declaration
Function AddYrs(const DT: TDateTime; const Yrs: Extended): TDateTime;
Description
Fractional portion of Year is assumed to be related to 365.25 day years. Time portion preserved.
If Adding Years results in landing on Feb 29 in a non-leap year, then this will be converted to Feb 28.This only applies to the integral component of the Years Added. The fractional part always is added to the resultant Date/Time.
| Parameters |
| DT | Date/Time to process. |
| Yrs | Number of Years to Add - can be negative. |
Category
Date/Time Arithmetic Routines
Year Based Arithmetic RoutinesImplementation
function AddYrs (const DT: TDateTime; const Yrs: Extended): TDateTime;
var
Day, Month, Year: Integer;
begin
OptDecodeDateI (DT, Year, Month, Day);
Year := Year + Trunc (Yrs);
if not IsLeapYear (Year) and (Month = 2) and (Day = 29) then
Day := 28;
Result := OptEncodeDateI (Year, Month, Day) + Frac (Yrs) * 365.25
+ Frac (DT);
End; |
|
|