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

function THiSettlForm.Init:string;

begin  

dtp1.DateTime:=FDOM(Now);  

dtp2.DateTime:=LDOM(Now);

end; 

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 2012-11-19 10:03  许小东  阅读(155)  评论(0)    收藏  举报