AdjustDateYear Routines |
Unit
QESBPCSDateTime
Overloaded Variants |
Function AdjustDateYear(const D: TDateTime; const Year: Word): TDateTime; |
Function AdjustDateYear(const D: TDateTime; const Year: Integer): TDateTime; |
Declaration
Function AdjustDateYear(const D: TDateTime; const Year: Word): TDateTime;
Description
Makes 29 Feb of any year that is not a Leap year 1 Mar.
Parameters |
D | Date/Time to process. |
Year | Year to make the date in, eg 1999. |
Category
Date/Time Arithmetic Routines
Year Based Arithmetic RoutinesImplementation
function AdjustDateYear (const D: TDateTime; const Year: Word): TDateTime; var Day, Month, OldYear: Word; begin OptDecodeDateW (D, OldYear, Month, Day); if Year = OldYear then begin Result := Int (D); Exit; end; if not IsLeapYear (Year) and (Month = 2) and (Day = 29) then begin Month := 3; Day := 1; end; Result := OptEncodeDateW (Year, Month, Day); End; |
Declaration
Function AdjustDateYear(const D: TDateTime; const Year: Integer): TDateTime;Implementation
function AdjustDateYear (const D: TDateTime; const Year: Integer): TDateTime; var Day, Month, OldYear: Integer; begin OptDecodeDateI (D, OldYear, Month, Day); if Year = OldYear then begin Result := Int (D); Exit; end; if not IsLeapYear (Year) and (Month = 2) and (Day = 29) then begin Month := 3; Day := 1; end; Result := OptEncodeDateI (Year, Month, Day); End; |
|