Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Get days count in month

Title: Get days count in month Implementation of this idea so: var DaysInYear: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); Days, Month, Year: Word; implementation ... procedure TForm1.Button1Click(Sender: TObject); begin Month:=StrToInt(Edit1.Text); Year:=StrToInt(Edit2.Text); if (IsLeapYear(Year)=True)and(Month=2) then Days:=DaysInYear[Month]+1 else Days:=DaysInYear[Month]; Label1.Caption:=IntToStr(Days)+' days in '+Edit2.text+' year'; end; procedure TForm1.FormCreate(Sender: TObject); var Present: TDateTime; begin Present:=Now; DecodeDate(Present, Year, Month, Days); Edit1.Text:=IntToStr(Month); Edit2.Text:=IntToStr(Year); end;