function MonthEnd(Date:TDateTime):TDateTime;
var
Year, Month, Day{, Hour, Min, Sec, MSec}: Word;
T:String;
begin
Result:=0;
DecodeDate(Date, Year, Month, Day);
T:=IntToStr(Year)+'-'+IntToStr(Month)+'-';
case Month of
1,3,5,7,8,10,12:Result:=StrToDate(T+'31');
4,6,9,11 :Result:=StrToDate(T+'30');
2 :if (Year mod 4 =0) and ( Year mod 100 <> 0 )
or (Year mod 400 =0 )
then
Result:=StrToDate(T+'29')
else
Result:=StrToDate(T+'28');
end;
end;
看看这个可能对你有启示
var
n : Word;
d : TDateTime;
var
n : Word;
d : TDateTime;
begin
d := StrToDate('2003-02-28');
n := DaysInAMonth(Yearof(d), Monthof(d));
case n of
28 : showmessage('平年二月');
29 : showmessage('闰年二月');
30 : showmessage('小月');
31 : showmessage('大月');
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s1,s2:word;
begin
s1:=strtoint(edit1.text);
s2:=strtoint(edit2.text);
edit3.text:=inttostr(DaysInAMonth(s1,s2));
end;