Know if a date is end of month  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 24/08/01

Tip accessed 487 times

 


It's to say: know if a date is the last day of its month


 procedure TForm1.Button1Click(Sender: TObject);

   {Devuelve TRUE si la fecha dada es el ultimo dia del mes
   Returns TRUE if the date is the last day of the month}
   function EsFinDeMes( const QueDia: TDateTime ): boolean;
   var
     Nada, ElDia: word;
   begin
     {Hallamos el dia del mes de la fecha +1}
     {Day of month of date+1}
     DecodeDate ( QueDia + 1, Nada, Nada, ElDia );
     {Si es 1, entonces es fin de mes}
     {If is 1 then is end of month}
     Result:=( ElDia=1 );
   end;

 begin
   {Ejemplo de llamada:}
   {A call Example:}
   if EsFinDeMes(Now) then ShowMessage( 'Hoy es fin de mes!+
   					#10+
                                        'Today is end of the month!');
 end;




The operation is as simple as to make a DecodeDate of the date + 1, this way we will obtain the following day to which we are inspecting; if it is day 1... it means that the day in question is month end.
Let us don't forget that the format TDateTime that Delphi uses uses the whole part to score the days lapsed from 12/30/1899, so if we added him a 1 to the date... we will obtain the following day.