我要在DateTimePicker1的OnChange里写个事件,就是当DateTimePicker1改变的时候,DateTimePicker2显示的是去年当天,即当DateTimePicker1为2009-3-22时,DateTimePicker2的日期为2008-3-22,这个事件怎么写? 

解决方案 »

  1.   


    DateTimePicker2.DateTime := IncYear(DateTimePicker1.DateTime,-1)
      

  2.   

    行了,要加一句 uses DateTils;
    自己给分自己,呵呵
      

  3.   

    Date   function   
        
      Returns   the   current   date.   
        
      DateDelta   constant   
        
      Specifies   the   correction   factor   when   computing   the   difference   between   two   date   and   time   types   that   do   not   begin   in   the   same   year.   
        
      DateTimeToFileDate   function   
        
      Converts   a   TDateTime   object   to   a   DOS   date-and-time   value.   
        
      DateTimeToStr   function   
        
      Converts   a   TDateTime   value   to   a   string.   
        
      DateTimeToString   procedure   
        
      Converts   a   TDateTime   value   to   a   string   using   a   specified   Format.   
        
      DateTimeToSystemTime   procedure   
        
      Converts   a   TDateTime   value   into   the   Win32   API's   TSystemTime   type.   
        
      DateTimeToTimeStamp   function   
        
      Converts   a   TDateTime   value   into   the   corresponding   TTimeStamp   value.   
        
      DateToStr   function   
        
      Converts   a   TDateTime   value   to   a   string.   
        
      DayOfWeek   function   
        
      Returns   the   day   of   the   week   for   a   specified   date.   
        
      DecodeDate   procedure   
        
      Returns   Year,   Month,   and   Day   values   for   a   TDateTime   value.   
        
      DecodeTime   procedure   
        
      Breaks   a   TDateTime   value   into   hours,   minutes,   seconds,   and   milliseconds.   
        
      EncodeDate   function   
        
      Returns   a   TDateTime   value   that   represents   a   specified   Year,   Month,   and   Day.   
        
      EncodeTime   function   
        
      Returns   a   TDateTime   value   for   a   specified   Hour,   Min,   Sec,   and   MSec.   
        
      FormatDateTime   function   
        
      Formats   a   TDateTime   value.   
        
      IncMonth   function   
        
      Returns   a   date   shifted   by   a   specified   number   of   months.   
        
      IsLeapYear   function   
        
      Indicates   whether   a   specified   year   is   a   leap   year.   
        
      MSecsPerDay   constant   
        
      Specifies   the   number   of   milliseconds   per   day.   
        
      MSecsToTimeStamp   function   
        
      Converts   a   specified   number   of   milliseconds   into   a   TTimeStamp   value.   
        
      Now   function   
        
      Returns   the   current   date   and   time.   
        
      ReplaceDate   procedure   
        
      Replaces   the   date   portion   of   a   TDateTime   value   with   a   specified   date.   
        
      ReplaceTime   procedure   
        
      Replaces   the   time   portion   of   a   TDateTime   value   with   a   specified   time.   
        
      SecsPerDay   constant   
        
      Indicates   the   number   of   seconds   per   day.   
        
      StrToDate   function   
        
      Converts   a   string   to   a   TDateTime   value.   
        
      StrToDateTime   function   
        
      Converts   a   string   to   a   TDateTime   value.   
        
      StrToTime   function   
        
      Converts   a   string   to   a   TDateTime   value.   
        
      SystemTimeToDateTime   function   
        
      Converts   a   TSystemTime   value   into   a   TDateTime   value.   
        
      Time   function   
        
      Returns   the   current   time.   
        
      TimeStampToDateTime   function   
        
      Converts   a   TTimeStamp   value   into   the   corresponding   TDateTime   value.   
        
      TimeStampToMSecs   function   
        
      Converts   a   TTimeStamp   value   into   an   absolute   number   of   milliseconds.   
        
      TimeToStr   function   
        
      Returns   a   string   that   represents   a   TDateTime   value.