怎么知道月末是31号还是30还是28?

解决方案 »

  1.   

    function IsLeapYear(AYear: Integer): Boolean;
    begin
      Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 = 0));
    end;function DaysPerMonth(AYear, AMonth: Integer): Integer;
    const
      DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    begin
      Result := DaysInMonth[AMonth];
      if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result); { leap-year Feb is special }
    end;
      

  2.   

    下面的函数返回指定日期的所在月的最后一天的日期: 
    function LastDayOfMonth(Dat: TDate): TDate;varD, M, Y : Word;beginDecodeDate(IncMonth(Dat, 1), Y, M, D);Result := EncodeDate(Y, M, 1) - 1;end;
      

  3.   

    delphi上本身没有这样的函数。
    本站有好多这样对日期的处理函数,看 看吧
      

  4.   

    use DateUtils;function DaysInAMonth(const AYear, AMonth: Word): Word;如:
    showmessage(inttostr(DaysInAMonth(2003,4)));
      

  5.   

    回复人: belllab(bell) ( ) 信誉:100  2003-05-15 10:51:00  得分:0 
     
     
      将时间设为下一月的1号,再将此日期-1就是此月的最后一天
      
     
    ------就这样做,
      

  6.   

    呵呵,一种办法也用得着重复这么多次?sigh.....
      

  7.   

    // 取得本月的最后一天
    function LastDayOfCurrentMonth: TDate;
    var
       Y, M, D: Word;
    begin
       DecodeDate(Now, Y, M, D);
       Inc(M);
       if M > 12 then begin
          Y := Y + 1;
          M := 1;
       end;
       Result := EncodeDate(Y, M, 1) - 1;
    end;其它月类似!