//日期3=日期2-日期1(格式:YYYY-MM-DD)
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit3.text :=inttostr(trunc(StrToDate(edit2.text) - StrToDate(edit1.text)));
end;//日期4=日期1加1(格式:YYYY-MM-DD)
procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit4.text :=DateToStr(Succ(trunc(StrToDate(edit1.text))));
end;//日期5=日期1格式化(变成YYYYMMDD)
procedure TForm1.Button3Click(Sender: TObject);
begin
  Edit5.text :=FormatDateTime('yyyymmdd',StrToDate(edit1.text));
end;//日期6=日期4格式化(变成YYYYMMDD)
procedure TForm1.Button4Click(Sender: TObject);
begin
  Edit6.text :=FormatDateTime('yyyymmdd',StrToDate(edit4.text));
end;
//日期递增(格式:YYYY-MM-DD)
procedure TForm1.Button5Click(Sender: TObject);
begin
  Edit7.text :=DateToStr(Succ(trunc(StrToDate(edit7.text))));
end;//格式化递增
procedure TForm1.Button6Click(Sender: TObject);
begin
  Edit8.text :=FormatDateTime('yyyy-mm-dd',(Succ(trunc(StrToDate(edit8.text)))));
  Edit9.text :=FormatDateTime('yyyymmdd',StrToDate(edit8.text));
end;

解决方案 »

  1.   

    来我给你加点:
    ///////////////////////////////////////////////////////////////////////////
    // 功能:获得某日期所在月份的第一天                                      //
    // 入口参数:TDateTime 某日期                                            //
    // 返回值:  某日期所在月份的第一天                                      //
    ///////////////////////////////////////////////////////////////////////////
    function MonthBegin(Date:TDateTime):TDateTime;
    var
     T:String;
    var
     Year, Month, Day{, Hour, Min, Sec, MSec}: Word;
    begin
     DecodeDate(Date, Year, Month, Day);
     T:=IntToStr(Year)+'-'+IntToStr(Month)+'-';
     Result:=StrToDate(T+'1')
    end;///////////////////////////////////////////////////////////////////////////
    // 功能:获得某日期所在月份的最后一天                                    //
    // 入口参数:TDateTime 某日期                                            //
    // 返回值:  某日期所在月份的最后一天                                    //
    ///////////////////////////////////////////////////////////////////////////
    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;///////////////////////////////////////////////////////////////////////////
    // 功能:获得开始日期到结束日期的天数                                    //
    // 入口参数:Date1,Date2 开始日期结束日期                                //
    // 返回值:天数                                                          //
    ///////////////////////////////////////////////////////////////////////////function DateToDateOfDayS(Date1,Date2:TDateTime):Integer;
    begin
      Result:= (DateTimeToTimeStamp(Date1).Date-DateTimeToTimeStamp(Date2).Date);
      if Result<0 then Result:=-Result;
        Result:=Result+1;
    end;
      

  2.   

    好,顶!!!
    根据月份,判断!
    Case语句就搞定了!