insert into Teacher(ComeTime) values(getdate())--插入数据库数据格式'2010-7-23 22:22:39'select getdate()--显示格式'2010-07-23 22:25:04.090'问题:
(1)同样是getdate()函数,前者是插入到数据库的数据,后者在数据库查询器里显示,格式怎么不一样
(2)怎么使的插入insert到数据库的数据格式变成'2010-07-23 22:22:39'即在7前面补全0
(3)select getdate()所显示的最后090是什么

解决方案 »

  1.   

    问题1:你的cometime字段的数据类型应该是smalldatetime,这个类型是精确到秒。。
    问题3:090是毫秒数
      

  2.   

    虽然插入的数据是系统时间,但ComeTime的类型是什么?
    这个有差别是正常。
      

  3.   


    comtime 是datetime类型的,我现在不是说精确的问题,我是想说我数据库cometime字段插入的数据是'2010-7-23 22:22:39',我想要'2010-07-23 22:22:39',即小于10的,前面补个0,7要显示成07
      

  4.   


    --第二个问题,楼主是什么环境?我这里运行如下:
    create table teacher(ComeTime smalldatetime)
    insert into Teacher(ComeTime) values(getdate())
    goselect * from teacher/*结果:
    ComeTime
    -----------------------
    2010-07-23 22:42:00
      

  5.   

    (3)datetime 的精度可以达到毫秒级,.090 表示90毫秒
    (2)select convert(varchar,getdate(),120) --120 yyyy-mm-dd hh:mi:ss(24h)select convert(varchar,getdate(),121) --121 yyyy-mm-dd hh:mi:ss.mmm(24h)
    (1)如果是ComeTime 是datetime 的应该显示格式应该与数据库设置有关,我的是SQL 2005 sqlexpress 中文版,安装时采用默认设置,时间显示的是yyyy-mm-dd hh:mi:ss.mmm(24h)格式。declare @tb table  (ComeTime datetime)
    insert into @tb (ComeTime) values( getdate())
    select * from @tb
    /*
    (1 row(s) affected)
    ComeTime
    -----------------------
    2010-07-23 22:44:49.640(1 row(s) affected)*/
      

  6.   


    DECLARE @T TABLE ([Time] datetime)
    INSERT INTO @T 
    SELECT GETDATE()
    SELECT * FROM @T/*(1 行受影响)
    Time
    -----------------------
    2010-07-23 22:44:58.040    --040为毫秒(1 行受影响)*/
      

  7.   

    http://blog.csdn.net/ldslove/archive/2010/05/06/5563768.aspx
      

  8.   

    (1)同样是getdate()函数,前者是插入到数据库的数据,后者在数据库查询器里显示,格式怎么不一样
    --我认为楼上回答到smalldatetime的都对。
    (2)怎么使的插入insert到数据库的数据格式变成'2010-07-23 22:22:39'即在7前面补全0
    --如果为了看起来好看,处理的方法很多,可以在查询时转换处理,如:select convert(varchar,datecol,120) from tb
    --也可以使用datetime类型(但这个直接查询显示的格式跟操作系统语言环境设置有关)
    (3)select getdate()所显示的最后090是什么
    --毫秒