Author: Radikal Q3
Kwow if a date is end of month
Answer:
It's to say: know if a date is the last day of its month.
1 2 procedure TForm1.Button1Click(Sender: TObject);
3 4 {Devuelve TRUE si la fecha dada es el ultimo dia del mes5 Returns TRUE if the date is the last day of the month}6 function IsMonthEnd( const Day: TDateTime ): boolean;
7 var8 Nada, ElDia: word;
9 begin10 {Hallamos el dia del mes de la fecha +1}11 {Day of month of date+1}12 DecodeDate ( Day+ 1, Nada, Nada, ElDia );
13 {Si es 1, entonces es fin de mes}14 {If is 1 then is end of month}15 Result:=( ElDia=1 );
16 end;
17 18 begin19 {Ejemplo de llamada:}20 {A call Example:}21 if IsMonthEnd(Now) then ShowMessage( 'Hoy es fin de mes!+
22 #10+
23 '
24 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 1to the date... we will obtain the following day.