比如:
2004-3-31
的上一月为
年:2004
月:2
2004-1-10
的上一月为
年:2003
月:12delphi里有没有这样的函数?

解决方案 »

  1.   

    if monthof(now)=1 then result:=12 else result:=monthof(now)-1
      

  2.   

    uses Dateutils
    function YearOf(const AValue: TDateTime): Word;
    function MonthOf(const AValue: TDateTime): Word;function IncMonth(const DateTime: TDateTime; NumberOfMonths: Integer = 1): TDateTime;
      

  3.   

    自己写个吧。
    procedure GetPrevNy(var year,mon:string;d:TDateTime);
    var
      s:string;
    begin
      s:=FormatDateTime('yyyymm',StrToDate(FormatDateTime('yyyy-mm',d)+'-01')-1);
      year:=Copy(s,1,4);
      mon:=Copy(s,4,2);
    end;
      

  4.   

    写错了,最后应该是
    year:=Copy(s,1,4);
      mon:=Copy(s,5,2);
      

  5.   

    showmessage('今天的上一个月是' + inttostr(Yearof(incMonth(date, -1))) + '年' + inttostr(monthof(incMonth(date, -1))) + '月');
      

  6.   

    uses 
      DateUtilsshowmessage('今天的上一个月是' + inttostr(Yearof(incMonth(date, -1))) + '年' + inttostr(monthof(incMonth(date, -1))) + '月');