有没有函数:输入年和月,输出这月的最后一天的日数?是31号还是30,还是28,29?

解决方案 »

  1.   

    Rx控件中有一个函数:
    function DaysPerMonth(AYear, AMonth: Integer): Integer;
    可以实现。
      

  2.   

    uses DateUtils;EndOfTheMonth(now)  //最后一天或者function LastDayOfMonth(Dat: TDate): TDate;
    var
       D, M, Y : Word;
    begin
       DecodeDate(IncMonth(Now, 1), Y, M, D);
       Result := EncodeDate(Y, M, 1) - 1;
    end;
      

  3.   

    同意 yzykjh(爱吃子姜的人)
      

  4.   

    yzykjh(爱吃子姜的人) 说的这个方法不错呀!
      

  5.   

    ///////////////////////////////////////////////////////////////////////////
    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;
      

  6.   


    uses DateUtilsfunction DaysInAMonth(const AYear, AMonth: Word): Word;
      

  7.   

    yzykjh(爱吃子姜的人)
    aiirii(ari)小弟佩服!
      

  8.   

    function DaysInAMonth(const AYear, AMonth: Word): Word;
    中间怎么写呀!不能直接调用!谢谢!