function TForm1._DayCountOfThisMonthOfDate(ADate: TDateTime): Word; var Year, Month, Day : Word; TmpDate : TDateTime; begin DecodeDate(ADate, Year, Month, Day); Month:=Month+1; if (Month>12) then begin Month:=1; Year:=Year+1; end; TmpDate:=EncodeDate(Year, Month, 1); DecodeDate(TmpDate-1, Year, Month, Day); result := Day; end;
//uses DateUtils; //返回本月最后一天 function GetLastDayOfMonth(ADate: TDateTime): TDateTime; var AYear, AMonth, ADay: Word; FDate, FDate1: TDateTime; begin FDate := IncMonth(ADate); DecodeDate(FDate,AYear,AMonth,ADay); FDate1 := EncodeDate(AYear,AMonth,1); Result := FDate1 - 1; end;
var Year, Month, Day : Word;
TmpDate : TDateTime;
begin
DecodeDate(ADate, Year, Month, Day); Month:=Month+1;
if (Month>12) then
begin
Month:=1;
Year:=Year+1;
end; TmpDate:=EncodeDate(Year, Month, 1);
DecodeDate(TmpDate-1, Year, Month, Day); result := Day;
end;
//返回本月最后一天
function GetLastDayOfMonth(ADate: TDateTime): TDateTime;
var
AYear, AMonth, ADay: Word;
FDate, FDate1: TDateTime;
begin
FDate := IncMonth(ADate);
DecodeDate(FDate,AYear,AMonth,ADay);
FDate1 := EncodeDate(AYear,AMonth,1);
Result := FDate1 - 1;
end;
showmessage(Inttostr(DaysInMonth(now)));