For Newbie

Tuesday, 15 November 2011

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


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;

Share on Facebook
Share on Twitter
Share on Google+

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