--> Tricks to know the number of days in a given year. | Delphi Tips Trick

For Newbie

Tuesday 15 November 2011

Tricks to know the number of days in a given year.

| Tuesday 15 November 2011

Function declaration:
/ / Based on Value Year:
totalday function (const t: Word): Integer;
begin
   if IsLeapYear (t) then Result: = 366
   else Result: = 365;
end;

/ / Based on Date:
totalday Date function (const d: TDate): Integer;
var
   tg, bl, th: Word;
begin
   DecodeDate (d, th, bl, tg);
   Result:  totalday (th);
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   Edit1.Text: = IntToStr (totalday  (2010));
   {When Using Date Time Picker
   Edit1.Text: = IntToStr (totalday Date (DateTimePicker1.Date));}
end;

Related Posts

No comments: