GetLastDayOfQuarter Routines
Returns Last Day of the Quarter, for a given Date/Time - Time portion preserved or Returns Last Day of the Quarter, for a given Quarter and Year.

Unit
QESBPCSDateTime

Overloaded Variants
Function GetLastDayOfQuarter(const DT: TDateTime): TDateTime;
Function GetLastDayOfQuarter(const Qtr: Byte; const Year: Word): TDateTime;
Function GetLastDayOfQuarter(const Qtr, Year: Integer): TDateTime;

Declaration
Function GetLastDayOfQuarter(const DT: TDateTime): TDateTime;

Parameters
DT Date/Time to process.
Qtr Quarter No, 1 through 4.
Year 4-digit Year such as 1999.

Category
Date/Time Arithmetic Routines

Implementation

function GetLastDayofQuarter (const DT: TDateTime): TDateTime;
var
     D, M, Y: Integer;
begin
     OptDecodeDateI (DT, Y, M, D);
     case M of
          1..3:
               begin
                    M := 3;
                    D := 31;
               end;
          4..6:
               begin
                    M := 6;
                    D := 30;
               end;
          7..9:
               begin
                    M := 9;
                    D := 30;
               end;
          10..12:
               begin
                    M := 12;
                    D := 31;
               end;
     end;
     Result := OptEncodeDateI (Y, M, D) + Frac (DT);
End;

Declaration
Function GetLastDayOfQuarter(const Qtr: Byte; const Year: Word): TDateTime;

Implementation

function GetLastDayofQuarter (const Qtr: Byte; const Year: Word): TDateTime;
var
     D, M: Word;
begin
     case Qtr of
          1:
               begin
                    M := 3;
                    D := 31;
               end;
          2:
               begin
                    M := 6;
                    D := 30;
               end;
          3:
               begin
                    M := 9;
                    D := 30;
               end;
          4:
               begin
                    M := 12;
                    D := 31;
               end;
     else
          begin
               M := 0;
               D := 0;
          end;
     end;
     Result := OptEncodeDateW (Year, M, D);
End;

Declaration
Function GetLastDayOfQuarter(const Qtr, Year: Integer): TDateTime;

Implementation

function GetLastDayofQuarter (const Qtr, Year: Integer): TDateTime;
var
     D, M: Integer;
begin
     case Qtr of
          1:
               begin
                    M := 3;
                    D := 31;
               end;
          2:
               begin
                    M := 6;
                    D := 30;
               end;
          3:
               begin
                    M := 9;
                    D := 30;
               end;
          4:
               begin
                    M := 12;
                    D := 31;
               end;
     else
          begin
               M := 0;
               D := 0;
          end;
     end;
     Result := OptEncodeDateI (Year, M, D);
End;


HTML generated by Time2HELP
http://www.time2help.com