第一天当然容易:就是年+月+‘1’
tmpdate:=strtodate(inttostr(yearof(date))+'-'+inttostr(monthof(date))+'-01');
麻烦出在最后一天:这样处理!
var TmpDate:TDate;
    tmpstr:string;
    tmpint1,tmpint2:integer;
begin
tmpint1:=yearof(date);
tmpint2:=monthof(date);
if month<>12 then//不是最后一个月
tmpdate:=strtodate(inttostr(tmpint1)+'-'+inttostr(tmpint2)+'-01')-1
//下个月的1号后退一天
else
tmpdate:=strtodate(inttostr(tmpint1-1)+'-01-01')-1;//如果当前腊月下一年的1月1号后退一天
end;

解决方案 »

  1.   

    第一天当然容易:就是年+月+‘1’
    tmpdate:=strtodate(inttostr(yearof(date))+'-'+inttostr(monthof(date))+'-01');
    麻烦出在最后一天:这样处理!
    var TmpDate:TDate;
        tmpstr:string;
        tmpint1,tmpint2:integer;
    begin
    tmpint1:=yearof(date);
    tmpint2:=monthof(date);
    if month<>12 then//不是最后一个月
    tmpdate:=strtodate(inttostr(tmpint1)+'-'+inttostr(tmpint2)+'-01')-1
    //下个月的1号后退一天
    else
    tmpdate:=strtodate(inttostr(tmpint1-1)+'-01-01')-1;//如果当前腊月下一年的1月1号后退一天
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      MonthBegin,MonthEnd,NowDate:TDateTime;
      Year,Month,Day:Word;
    begin
      NowDate := Now;
      DecodeDate(NowDate, Year, Month, Day);
      MonthBegin := EncodeDate(Year,Month,1);
      if Month<12 then
        MonthEnd := EncodeDate(Year,Month+1,1)
      else
        MonthEnd := EncodeDate(Year+1,1,1);
      MonthEnd := MonthEnd-1;
    end;
      

  3.   

    判断润年
    if TmpDate.isleapyear then
    //润年
    else
    //不是润年
      

  4.   

    得到给出日期中的最后一天函数:
    function getlastday(adate:Tdate):Tdate;
    var
    w1,w2,w3:word;
    begin
    DecodeDate(adate,w1,w2,w3);
    case round(w2) of
     4,6,9,11: begin
     w3:=30;
     end;
     2:
     begin
    if IsLeapYear(w1) then w3:=29
    else w3:=28;
     end;
     1,3,5,7,8,10,12:w3:=31;
     end;
     result:=EncodeDate(w1,w2,w3);
    end;第一天函数:
    function getfirstday(adate:Tdate):Tdate;
    var
    w1,w2,w3:word;
    begin
    DecodeDate(adate,w1,w2,w3);
      result:=result:=EncodeDate(w1,w2,1);
    end;
      

  5.   

    //月初
    function BOFM(Date1:TDateTime):TDateTime;
    var
    Year1,Month1,Day1:word;
    begin
      DecodeDate(Date1, Year1, Month1, Day1);
      Result := EncodeDate(Year1, Month1, 1);
    end;//月末
    function EOFM(Date1:TDateTime):TDateTime;
    var
    Year1,Month1,Day1:word;
    begin
    DecodeDate(Date1, Year1, Month1, Day1);
      Result := EncodeDate(Year1, Month1, DayOfMonth(Year1,Month1) );
    end;
      

  6.   

    先设置:ShortDateFormat:='YYYY-MM-DD';
    本月第一天:strtodate(formatdatetime('yyyy-mm-01',now()))
    本月的最后一天:incmonth(strtodate(formatdatetime('yyyy-mm-01',now())),1)-1