DayOfMonth2Date Routines |
Unit
QESBPCSDateTime
Overloaded Variants |
Declaration
Function DayOfMonth2Date(const DOMType: TESBDOMType; const DOW: Byte; const Month, Year: Word): TDateTime;
Description
Thus can be used to find the first Wednesday, Last Monday, etc. DOMType can be one of the following:
domFirst - First occurrence in a Month.
domSecond - Second occurrence in a Month.
domThird - Third occurrence in a Month.
domFourth - Fourth occurrence in a Month.
domLast - Last occurrence in a Month.
Parameters |
DOMType | the desired Day of Month Type. |
DOW | the Day of Week, 1 = Sunday, 7 = Saturady. |
Month | the month of the year, 1 = Jan, 12 = Dec. |
Year | 4-digit year such as 1999. |
Returns
the Date uniquely defined by the above.
Category
Date/Time Arithmetic Routines
Month Based Arithmetic RoutinesImplementation
function DayOfMonth2Date (const DOMType: TESBDOMType; const DOW: Byte; const Month, Year: Word): TDateTime; var Ofs: Integer; DT: TDateTime; begin if (DOW < 1) or (DOW > 7) then raise EConvertError.Create (rsInvalidDOW); if (Month < 1) or (Month > 12) then raise EConvertError.Create (rsInvalidMonth); if DOMType < domLast then begin DT := GetFirstDayOfMonth (Month, Year); Ofs := DOW - DayOfWeek (DT); if Ofs < 0 then Ofs := Ofs + 7; Result := DT + Ofs + 7 * Integer (DOMType); end else begin DT := GetLastDayOfMonth (Month, Year); Ofs := DayofWeek (DT) - DOW; if Ofs < 0 then Ofs := Ofs + 7; Result := DT - Ofs; end; End; |
Declaration
Function DayOfMonth2Date(const DOMType: TESBDOMType; const DOW, Month, Year: Integer): TDateTime;Implementation
function DayOfMonth2Date (const DOMType: TESBDOMType; const DOW, Month, Year: Integer): TDateTime; var Ofs: Integer; DT: TDateTime; begin if (DOW < 1) or (DOW > 7) then raise EConvertError.Create (rsInvalidDOW); if (Month < 1) or (Month > 12) then raise EConvertError.Create (rsInvalidMonth); if DOMType < domLast then begin DT := GetFirstDayOfMonth (Month, Year); Ofs := DOW - DayOfWeek (DT); if Ofs < 0 then Ofs := Ofs + 7; Result := DT + Ofs + 7 * Integer (DOMType); end else begin DT := GetLastDayOfMonth (Month, Year); Ofs := DayofWeek (DT) - DOW; if Ofs < 0 then Ofs := Ofs + 7; Result := DT - Ofs; end; End; |
|