一段时间2010-11-12 到2011-03-12
想得到这样的
2010年11月,2010年12月,2011年1月,2011年2月 

解决方案 »

  1.   

    给你一个函数参考一下function monthdiff(startdate,enddate:TDateTime):integer;
    var
        date1,date2:string;
        Syear,Eyear,Smonth,Emonth:integer;
    begin
        date1:=formatdatetime('yyyy-mm-dd',startdate);
        date2:=formatdatetime('yyyy-mm-dd',enddate);
        Syear:=strtoint(copy(date1,1,4));
        smonth:=strtoint(copy(date1,6,2));
        Eyear:=strtoint(copy(date2,1,4));
        Emonth:=strtoint(copy(date2,6,2));
        if (syear-eyear)>0 then
          begin
              if (smonth-emonth)>0 then
              result:=(syear-eyear)*12+(smonth-emonth)
              else
              result:=(syear-eyear)*12+(smonth-emonth);
          end
        else if  (syear-eyear)=0 then
              result:=abs(smonth-emonth)
        else
             begin
                if (smonth-emonth)>0 then
                result:=(abs(syear-eyear))*12+(-1)*(smonth-emonth)
                else
                result:=abs(syear-eyear)*12+abs(smonth-emonth);
             end;
    end;
      

  2.   


    uses
      DateUtils;begin
      date := StrToDate('2010-11-12');
      endDate := StrToDate('2011-03-12');
      while date < endDate do
      begin
        ShowMessage(FormatDateTime('yyyy年mm月', date));
        IncMonth(date);
      end;
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      d1,d2:TDate;
    begin
      d1:=EncodeDate(2010,11,12);
      d2:=EncodeDate(2011,3,12);
      Memo1.Lines.Add(FormatDateTime('yyyy年m月',d1));
      while d1 < d2 do begin
        if FormatDateTime('dd',d1)='01' then begin
          Memo1.Lines.Add(FormatDateTime('yyyy年m月',d1));
        end;
        d1:=d1+1;
      end;end;end.
      

  4.   

    改成这样
    if FormatDateTime('dd',d1)='12' then
      

  5.   

    假设 date1 为2010年11月12日,date2为2011年3月12日,且都为TDateTime类型的数据,则
    date0 := IncMonth(date1) 则date0为2010.12.12,与此类似,直到返回值小于date2
    输出的时候,使用formatdatetime('yyyy年mm月',date0)就可以
      

  6.   

    FormatDateTime('yyyy年mm月', date)
      

  7.   


    这个好像是要返回值的
    date := IncMonth(date);
      

  8.   

    如果用oracle的话,可以在数据库中运行,一条sql就搞定!
      

  9.   

    select to_char(to_date('2010-11-12','yyyy-mm-dd'),'yyyy"年"mm"月"dd"日"') from dual结果:2010年11月12日