Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Get the amount of days of a given month

Title: Get the amount of days of a given month Question: How to calculate the days of a month considering the leap year Answer: uses SysUitls; // IsLeapYear ... function DaysOfMonth(Date: TDateTime): integer; var y, m, d: Word; begin DecodeDate( Date, y, m, d ); case m of 2: if IsLeapYear(y) then Result:=29 else Result:=28; 1,3,5,7,8,10,12: Result:=31; 4,6,9,11: Result:=30; end; end;