为什么要这样??
这样行吗?
var
  year,Month,day: Word;
  qDate: TDate;
begin
  DecodeDate(Now, year, Month, day);
  qDate := EncodeDate(year, month, day);
  showmessage(DatetimeTostr(qDate));

解决方案 »

  1.   

    table1.FieldByName('时间').asdate:=datetimepicker4.date;
    //时间自动设为00:00:00,从数据库中调出时,将忽略该时间。
      

  2.   

    先用datetimepicker4.date:=trunc(datetimepicker4.date);
    把时间整成0:0:0看行不行?
      

  3.   

    var Year,Month,Day:Word;
    begin
      DecodeDate(datetimepicker4.date,Year,Month,Day);
      Table1.Fields[1].AsDateTime:=EncodeDate(Year,Month,Day);//save Date,not Time
    end;
      

  4.   

    使用formatdatetime函数table1.edit;
    table1.FieldByName('时间').asdatetime:=formatdatetime('yyyy-mm-dd',datetimepicker4.datetime);       ______OK!!!
      

  5.   

    这不是Delphi的要解决的问题,是SQLSERVER没有Date而只有datetime类型,你自然不能只存入Date了所以你只能是在读出或在查询时在处理此字段,把Time 截断!
      

  6.   

    DATE就用DATETIMEPICKER来取,记得KIND:=DATE,时间嘛,既然你不用,随机取就好了,
    不然取NOW的值也行
      

  7.   

    FieldByName('时间').asdatetime:= strtodate(formatdatetime('yyyy-mm-dd', DateTimePicker1.Date));
      

  8.   

    如果不要时间,另一办法对日期取整:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        TDateTime rq=Now();
        rq=(TDateTime)((int)rq);  // 取整
        ShowMessage(rq);
    }
    这是C++BUILDER
    的办法,改成DELPHI就行了
    结果:时间没有了,实际是 0:0
      

  9.   

    同意gxdq(石老人) 的说法,用formatdatetime函数绝对没问题.
      

  10.   

    这个问题很简单,我告诉你一个方法,百试不爽.
    只需在FormCreate事件中写上(datetimepicker4.datetime:=Date;),然后程序中不论何时取
    table1.FieldByName('时间').asdatetime:=datetimepicker4.date,均不含时间.
      

  11.   

    formatdatetime会出现错误
    我用以下语句会出现错误
    table1.edit;
    table1.FieldByName('出生年月').asdatetime:=formatdatetime('yyyy-mm-dd',datetimepicker1.datetime);错误信息.
    [Error] input1.pas(662): Incompatible types: 'TDateTime' and 'String'
    怎样解决?
      

  12.   

    formatdatetime会出现错误
    我用以下语句会出现错误
    table1.edit;
    table1.FieldByName('出生年月').asdatetime:=formatdatetime('yyyy-mm-dd',datetimepicker1.datetime);错误信息.
    [Error] input1.pas(662): Incompatible types: 'TDateTime' and 'String'
    怎样解决?
      

  13.   

    FormatDateTime() 返回的是串类型AnsiString,不是TDateTime类型
    你们肯定是错了;
    我已经提了,只要对日期取整,时间变没有了,
        TDateTime rq=Now();
        rq=(TDateTime)((int)rq);  // 日期取整
        ShowMessage(rq);
    C++这么简单,DELPHI肯定也很简单
      

  14.   

    同意gxdq(石老人) 的说法,用formatdatetime函数绝对没问题. 
    不过要改一下:
    table1.FieldByName('时间').asstring:=formatdatetime('yyyy-mm-dd',datetimepicker4.datetime);
      

  15.   

    use FormateDateTime("yyyy-mm-dd",Now());