求一个月的第一天和最后一天

求一个月的第一天和最后一天:
function THiSettlForm.Init:string;
begin
  dtp1.DateTime:=FDOM(Now);
  dtp2.DateTime:=LDOM(Now);

function THiSettlForm.FDOM(Date: TDateTime): TDateTime;
var
    Year, Month, Day: Word;
  begin
    DecodeDate(Date, Year, Month, Day);
   //month:=dec(month);
    if Month >1  then
     dec(Month)
    else
     begin
      Month := 12;
      dec(year) ;
      end;
    Result := EncodeDate(Year, Month, 1);
end;

function THiSettlForm.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;

posted on 2009-09-08 17:28  舟山牙医  阅读(190)  评论(0)    收藏  举报

导航