数据中日期为2009.12.05 09:00:52的格式,想在select的时候将其转换为20091205或者转换为2009.12.05
用了这样方式不行:select * from c_logon where convert(varchar(10),oper_datetime,120) 其中:oper_datetime为日期的字段

解决方案 »

  1.   

    --日期转换参数,值得收藏
    select CONVERT(varchar, getdate(), 120 )
    2004-09-12 11:06:08select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
    20040912110608select CONVERT(varchar(12) , getdate(), 111 )
    2004/09/12select CONVERT(varchar(12) , getdate(), 112 )
    20040912select CONVERT(varchar(12) , getdate(), 102 )
    2004.09.12其它我不常用的日期格式转换方法:select CONVERT(varchar(12) , getdate(), 101 )
    09/12/2004select CONVERT(varchar(12) , getdate(), 103 )
    12/09/2004select CONVERT(varchar(12) , getdate(), 104 )
    12.09.2004select CONVERT(varchar(12) , getdate(), 105 )
    12-09-2004select CONVERT(varchar(12) , getdate(), 106 )
    12 09 2004select CONVERT(varchar(12) , getdate(), 107 )
    09 12, 2004select CONVERT(varchar(12) , getdate(), 108 )
    11:06:08select CONVERT(varchar(12) , getdate(), 109 )
    09 12 2004 1select CONVERT(varchar(12) , getdate(), 110 )
    09-12-2004select CONVERT(varchar(12) , getdate(), 113 )
    12 09 2004 1select CONVERT(varchar(12) , getdate(), 114 )
    11:06:08.177
      

  2.   

    select * from c_logon where convert(varchar(10),oper_datetime,112)select * from c_logon where convert(varchar(10),oper_datetime,102)
      

  3.   

    convert(varchar(10),cast('2009.12.05 09:00:52' as datetime),102)
      

  4.   


    select * from c_logon where replace(convert(varchar(10),oper_datetime,120),'.','-')
      

  5.   

    直接 convert(nvarchar(10),日期,102)...
      

  6.   

    select CONVERT(varchar(12) , getdate(), 102 )
    2004.09.12不错
      

  7.   

    create table tb(dt datetime)
    insert into tb values('2009.12.05 09:00:52')
    goselect convert(varchar(10),dt,120) dt from tb
    /*
    dt         
    ---------- 
    2009-12-05(所影响的行数为 1 行)
    */select convert(varchar(8),dt,112) dt from tb
    /*
    dt       
    -------- 
    20091205(所影响的行数为 1 行)
    */select convert(varchar(10),dt,102) dt from tb
    /*
    dt         
    ---------- 
    2009.12.05
    */
    drop table tb
      

  8.   

    上面已经给出答案。
    这是分别取出每个值,可以自己随意组合print '今天是'+datename(yy,getdate())+'年'+datename(mm,getdate())+'月'+datename(dd,getdate())+'日'+datename(hh,getdate())+'时'+datename(minute,getdate())+'分'+datename(ss,getdate())+'秒'+datename(dw,getdate())
      

  9.   

    很感激上面几位回复的朋友,但试了不行,不知什么原因,可能我说的不够明白,是这样的,有表一和表二,表一中的一个时间字段为:date1,表二中的一个时间字段为:date2,我想这样
    select top 1 * from 表一 where (varchar(10),date1,120)='"&rs("date2")&"'
    其中:date1的值为:2009-12-05 08:00:20,date2的值为:2009-12-05,想将表一的时间转换为跟表二的相等.我这样的转换法,之前一段时间可以的,但后来就行了,不知什么原因,