计算下月1号与该月1号之间的天数。
function getmonthdays(year,month:integer):Integer;
var
  nextmonth : integer;
  day1,day2 : date;
begin
  if month = 12 then 
    result := 31
  else
  beign
    nextmonth := month + 1;
    day1 := encodeday(year,month,1);
    day2 := encodeday(year,nextmonth,1);
    Result := Int(day2 - day1);
  end;
end;

解决方案 »

  1.   

    首选,你可以做一个长度为12的数组,如
    MaxDays:array [1..12] of integer;
    MaxDays[1]:=31;MaxDays[2]:=28 .........MaxDays[11]:=30;MaxDays[12]:=31;
    然后判断某年是否是闰年,规则如下:
    if ((year mod 400=0) or ((year mod 4=0) and (year mod 100<>0)) then
    begin
      MaxDays[2]:=29;//如果是闰年,将2月份变为29天
    end;
    如后就可以根据数组得出某月的最大天数.
    快快给分!!!!!!!
      

  2.   

    简单,如下:MonthDays[IsLeapYear(年份), 月份];在SysUtils单元中
      

  3.   

    //test ok
    function  DayMax(DateA:TDateTime):TDateTime;stdcall; 
       const kk:array[1..12] of Integer=
        (31,28,31,30,31,30,31,31,30,31,30,31);
     var Year,month,day:Word;
       begin
        DecodeDate(DateA,Year,Month,Day);
        if (((Year Mod 4)=0 ) and ((Year Mod 100)<>0)) or
         ((Year Mod 400)=0) then kk[2]:=29 else kk[2]:=28;
           Result:=EncodeDate(Year,Month,kk[Month])
       end;
      

  4.   

    有一个很简单的方法,用下个月一号减去一,然后再取day即可。
    如:要求6月份的天数,用7.1-1得6.30,然后再取day即得30
      

  5.   

    encodedate中的参数好像要求是word string怎么转换成word?
      

  6.   

    同意 zhboy(孔方兄) 的方法:
    简单,如下:MonthDays[IsLeapYear(年份), 月份];在SysUtils单元中.
      

  7.   

    其实不能这么烦的
    设定一个字符中:
    var  tdate:string ;
    month:integer;
    maxdate:string;
    begin 
    TDATE= '312831303130313130313030'
    maxdate=copy(tdate,(month*2-1),2)
    end ;
    是不是可行?????
      

  8.   

    case month of
    1,3,5,7,8,10,12:day := 31;
    4,6,9,11: day:=30;
    2: if year mod 4=0 then Day := 29 else Day:=28;也可以得出!办法是很多的,关键不在于去学别人怎么做;而在于去创造怎么做!!
      

  9.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Spin;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        Edit1: TEdit;
        SpinEdit1: TSpinEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    type
     day=28..31;
     month=(jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec);
     year=1900..2004;
    var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var days:day;
        months:month;
        years:year;
       leep:boolean;
    begin
    years:=spinedit1.value;
    edit1.text:='你选择了'+inttostr(spinedit1.value);
    if (years mod 400=0)or(years mod 4=0)and(years mod 100<>0) then
     leep:=true;
    memo1.lines.add(inttostr(spinedit1.value));
    memo1.Lines.add('****years****');
    for months:=jan to dec do
    begin
      case months of
       jan,mar,may,jul,aug,oct,dec:days:=31;
       apr,jun,sep,nov:days:=30;
       feb:if leep then
        days:=29
        else
        days:=28;
      end;
      case months of
       jan:memo1.Lines.add('一月'+' '+inttostr(days)+'天');
       feb:memo1.Lines.add('二月'+' '+inttostr(days)+'天');
       mar:memo1.Lines.add('三月'+' '+inttostr(days)+'天');
       apr:memo1.Lines.add('四月'+' '+inttostr(days)+'天');
       may:memo1.Lines.add('五月'+' '+inttostr(days)+'天');
       jun:memo1.Lines.add('六月'+' '+inttostr(days)+'天');
       jul:memo1.Lines.add('七月'+' '+inttostr(days)+'天');
       aug:memo1.Lines.add('八月'+' '+inttostr(days)+'天');
       sep:memo1.Lines.add('九月'+' '+inttostr(days)+'天');
       oct:memo1.Lines.add('十月'+' '+inttostr(days)+'天');
       nov:memo1.Lines.add('十一月'+' '+inttostr(days)+'天');
       dec:memo1.Lines.add('十二月'+' '+inttostr(days)+'天'+#13#10);
      end;
     end;end;end.