问题1、程序中如何指定每个月份的1号,比如我选择的是6月,然后dbgrideh1里面的日期字段就显示2004-6-1?我的意思是,在一个下拉菜单里选择6月份,那么dbgrid里面的某一列(其字段类型为日期)就显示为2004-6-1(默认时间可能是2004-6-10或者2004-6-22),反正保证第一行是6月份而且是1号?这如何实现呢?问题2、如果我第一行的日期是2004-6-1,那么第二行日期默认显示为2004-6-1,如果我将第二行日期改为2004-6-10则第三行日期默认为2004-6-10?

解决方案 »

  1.   

    数据库里原来没有日期数据的,就是我在下拉菜单里选择一个六月,然后确定,dbgrideh1里面就会自动生成2004-6-1,而不是默认的现在日期(例如现在是2004-6-17),如何生成呢?
      

  2.   


    var y,m,d:Word;
    DecodeDate(DateTimePicker1.Date, y,m,d);
    Query['field'] := EncodeDate(y,m,1);2 你需要自己记录最后一行的日期值。
      

  3.   

    1.DecodeDate() EncodeDate()
    2.事件写代码Returns a TDateTime value that represents a specified Year, Month, and Day.UnitSysutilsCategorydate/time routinesfunction EncodeDate(Year, Month, Day: Word): TDateTime;DescriptionEncodeDate returns a TDateTime value from the values specified as the Year, Month, and Day parameters.The year must be between 1 and 9999.Valid Month values are 1 through 12.Valid Day values are 1 through 28, 29, 30, or 31, depending on the Month value. For example, the possible Day values for month 2 (February) are 1 through 28 or 1 through 29, depending on whether or not the Year value specifies a leap year.If the specified values are not within range, EncodeDate raises an EConvertError exception.
      

  4.   

    Returns Year, Month, and Day values for a TDateTime value.UnitSysutilsCategorydate/time routinesprocedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);DescriptionThe DecodeDate procedure breaks the value specified as the Date parameter into Year, Month, and Day values. If the given TDateTime value is less than or equal to zero, the year, month, and day return parameters are all set to zero.