我想获得一个日期的所在的年初和年末的时间,例如:2005-02-28它的年初时间2005-01-01和年末时间2005-12-31,怎么做呢?请高手指点,谢谢!

解决方案 »

  1.   

    >>用膝盖都能想出来怎么做……
      

  2.   

    取出当前年份yyyy,拼接字符串生成yyyy-1-1和yyyy-12-31,再转成日期型,自己感觉有点ft!
      

  3.   

    ●procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word); 描述: 
    DecodeDate从一个TDateTime类型参数Date中分解出得到年份、月份、日子。
      

  4.   

    http://community.csdn.net/Expert/topic/3803/3803744.xml?temp=.4013025
      

  5.   

    DateUtils单元有现成的函数:function StartOfTheYear(const AValue: TDateTime): TDateTime;
                               function EndOfTheYear(const AValue: TDateTime): TDateTime;
      

  6.   

    use DateUtils  edit1.Text:=datetostr(StartOfAYear(yearof(strtodate('2005-02-28'))));
      edit2.Text:=datetostr(EndOfAYear(yearof(strtodate('2005-02-28'))));
      

  7.   

    function StartOfTheYear(const AValue: TDateTime): TDateTime;
    begin
      Result := EncodeDate(YearOf(AValue), 1, 1);
    end;function EndOfTheYear(const AValue: TDateTime): TDateTime;
    begin
      Result := EndOfTheDay(EncodeDate(YearOf(AValue), 12, 31));
    end;
      

  8.   

    DecodeDate(Date: TDateTime; var Year, Month, Day: Word); //分解日期
    EncodeDate(Year, Month, Day: Word): TDateTime  //组合日期
      

  9.   

    太难懂了,sorry,得用肢趾头才想得出来。
      

  10.   

    procedure TForm1.Button1Click(Sender: TObject);var
      Present: TDateTime;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
     begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
        + IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
        + IntToStr(Hour);
    end;