将日期转换成字符串

日期为2004-03-02   转为字符形式 20040302
日期为2004-3-2 转为字符形式也要为 20040302
将时间转换成字符串

时间为19:22:22 转为字符形式 192222
时间为1:1:1   转为字符形式也要为 010101
能够分辨24小时制与12小时制,统一按24小时输出字符串acess中有个字段为日期/时间型,但是我仅存放时间,怎样用sql查出来仅时间部分!谢谢!答案精彩另外加分!

解决方案 »

  1.   

    S := FormatDateTime('yyyyMMdd', Now);S := FormatDateTime('hhmmss', Now);
      

  2.   

    access 查日期部分比較簡單, 查部分時間的, 我也不會!
      

  3.   

    acess中有个字段为日期/时间型,但是我仅存放时间,怎样用sql查出来仅时间部分!这个我一直也没试验出来哦!
      

  4.   

    to 楼上,
    是这样的,但是我想用sql 查询这个字段的时候,让它已标准的时间格式现实,如果您有什么好方法,谢谢;数据库access 2000
      

  5.   

    Frac(now)取现在日期/时间的时间部分!
      

  6.   

    我好像没有发现有什么难度:
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    更正一下,日期是Delphi自动加上去的,从下面可以看出来
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ADOQuery1.Close;
      ADOQuery1.SQL.Text := 'Select * from TableOne where TimeValue > :StrartTime and TimeValue < :EndTime';
      ADOQuery1.Parameters.ParamValues['StrartTime'] := StrTotime('14:50');
      ADOQuery1.Parameters.ParamValues['EndTime'] := time;
      ADOQuery1.Open;
    end;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    procedure TForm1.ADOQuery1TIMEvalueGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
      Text := Sender.Value;
    end;
      

  7.   

    to WGYKING(【将要被封杀】) 
    您答案对于本题目是错误的!!!我想查询出来,比如
    select starttime from abc这个starttime是时间型的,但是返回 1899-12-30 18:00:09形式,我仅仅需要 18:00:09形式还有作为条件的时候,怎么用字符串连接的形式查出来,不需要参数形式谢谢
      

  8.   


    Formatdate('YYYYmmDDHHMMSS',Now); // 20040410173640
      

  9.   

    哦?
    你有没有好好看看代码?
    主要的处理就是在时间字段的OnGetText中的Text := Sender.Value一行
      

  10.   

    请问adoquery中有这个OnGetText事件吗?
    请问adoquery中有这个OnGetText事件吗?
    请问adoquery中有这个OnGetText事件吗?
      

  11.   

    ADOQuery1-->右键-->Fields Editor-->Add All Fields-->选择字段-->OnGetText事件
      

  12.   

    to WGYKING(【将要被封杀】) 
    兄弟,我的ADOQuery1.Connection 与
    ADOQuery1.SQL.Text都是动态赋予的
    不能像你那样用Fields Editor来处理的!但是还是谢谢你的答案!
      

  13.   

    sweat
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    事件处理过程也可以动态赋值啊!!
      

  14.   

    TForm1 = class(TForm)
        Button1: TButton;
        ADOQuery1: TADOQuery;
        procedure Button1Click(Sender: TObject);
        procedure ADOQuery1TimeValueGetText(Sender: TField; var Text: String; DisplayText: Boolean);  //This...
      private
      public
      end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ADOQuery1.Close;  ADOQuery1.FieldDefs.Clear;  With ADOQuery1.FieldDefs.AddFieldDef do
        begin
          Name := 'ID';
          DataType := ftWideString;
        end;  With ADOQuery1.FieldDefs.AddFieldDef do
        begin
          Name := 'TimeValue';
          DataType := ftTime;
        end;  ADOQuery1.FieldByName('TimeValue').OnGetText := ADOQuery1TimeValueGetText;  ADOQuery1.SQL.Text := 'Select * from TableOne where TimeValue > :StrartTime and TimeValue < :EndTime';
      ADOQuery1.Parameters.ParamValues['StrartTime'] := StrTotime('14:50');
      ADOQuery1.Parameters.ParamValues['EndTime'] := time;
      ADOQuery1.Open;
    end;procedure TForm1.ADOQuery1TimeValueGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
      Text := Sender.Value;
    end;
      

  15.   

    ADOQuery1.Open;
    ADOQuery1.FieldByName('TimeValue').OnGetText := ADOQuery1TimeValueGetText;
      

  16.   

    sqlscript := 'SELECT Count(day_card.empno) AS CountNumber FROM day_card';
            sqlscript := sqlscript+ '  where  day_card.date_day=#' + datetostr(dtpstart.Date+1) + '#  AND DATE_TIME>FORMAT('''+timestart+''',''HH:NN:ss'') AND DATE_TIME<FORMAT('''+timeend+''',''HH:NN:ss'')';
    with adoque do
    begin
    active:=false;
    sql.clear;
    sql.add(sqlscript)
    active:=true;
    end;
    ....
      

  17.   

    补充:     
       timestart:=timetostr('07:00');
       timeend:=timetostr('10:01' );'