Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function of getting the last day of the current month in Delphi
11-30-2009, 06:08 AM
Post: #1
Function of getting the last day of the current month in Delphi
This function returns type TDate and that represents last day of the current month. Here is the code :
Code:
function LastDayOfCurrentMonth: TDate;
var
  y,m,d:Word;
begin
  DecodeDate(now,y,m,d);
  m:=m+1;
  if m>12 then
  begin
    y:=y+1;
    m:=1;
  end;
  Result:=EncodeDate(y,m,1)-1;
end;
If you want to test this, you can use ShowMessage to show it, use this code :
Code:
ShowMessage(DateToStr(LastDayOfCurrentMonth));
Also if you want to find which day it is (Monday, Tuesday . . . Sunday) you need to use this code :
http://www.pro9ramming.com/day-in-week-b...t-160.html
That is in Pascal, but it is easy to optimize it for Delphi.

"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: