在delphi裡面怎麼取每個月的最後一天?

解决方案 »

  1.   

    uses
    DateUtils;function DaysInMonth(const AValue: TDateTime): Word;daysinmonth(date); //31
      

  2.   

    Unit DateUtilsfunction DayOfTheMonth(const AValue: TDateTime): Word;
      

  3.   

    錯了, 應該是:
    Unit DateUtilsfunction DaysInAMonth(const AYear, AMonth: Word): Word;
      

  4.   

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

  5.   

    傻一点的方法
    当前的时间为一个WORD值;
    加一后看看月份有没有变化,变化之前的一天为本月的最后一天
      

  6.   

    function LDOM(Date: TDateTime): TDateTime;
      var
        Year, Month, Day: Word;
      begin
        DecodeDate(Date, Year, Month, Day);
        if Month < 12 then inc(Month)
        else begin Month := 1; inc(Year) end;
        Result := EncodeDate(Year, Month, 1) - 1;
      end;
    调用示范
    -----------  procedure TForm1.Button1Click(Sender: TObject);
      begin
        ShowMessage(DateToStr(LDOM(Now)));
      end;