在数据库里有个字段是时间字段,格式:yyyy-mm-dd hh:mm:ss
用adoquery做查询,想要查询显示的结果为yyyy-mm
应该怎么写?

解决方案 »

  1.   

      ADOQuery.Close;
      ADOQuery.SQL.Text:='select convert(nvarchar(7),日期字段名,120) from 表名';
      ADOQuery.Open;
      

  2.   

    一个笨方法:转化为TDateTime,再提取相关信息。。
      

  3.   

    FormatDateTime('YYYY-MM',ADOQuery1.FieldByName('列名').AsDateTime);
      

  4.   

    to gzzai:
    我的数据库用的access,select convert(nvarchar(7),sh_date,120) from 表  convert不被识别
    to kaikai_kk:
    我是想放在:
    adoquery.close;
    adoquery.sql.add('********')里面使用,所以FormatDateTime不适用
      

  5.   

      ADOQuery1.Close;
      ADOQuery1.SQL.Text:='select format(d,'+QuotedStr('yyyy-mm')+') from 表1';
      ADOQuery1.Open;d 为日期类型的字段,表1 为数据表名
      

  6.   

    access的数据库与sql的数据库,有许多函数是不一致的。如果提问题时,能稍详细说明自己的情况,就能为自己节约时间,别人也不用去猜测。
      

  7.   

    to gzzai:
    select format(come_date,'+QuotedStr('yyyy-mm')+') from ls
    提示语法错误或者操作符丢失?请多指教。
      

  8.   

    或者,对比你的语句是否跟下面的一致:  ADOQuery1.Close;
      ADOQuery1.SQL.Text:='select format(come_date,'+QuotedStr('yyyy-mm')+') from ls';
      ADOQuery1.Open;