如何将当前时间取出来(不含日期)保存在一个numeric型字段中呢?日期我会存,但是纯时间我不知如何保存?
是这样的,我不想用datetime型来保存当前的时间,我想用数字才保存。
即用 int 型字段保存当前的日期,用 numeric 型字段保存当前的时间。
对于日期,可以用datediff()函数来进行日期与数字的转换,非常方便。
如:
select datediff(day,0,getdate())select cast(39858 as datetime)显示结果如下:
            
----------- 
39858(所影响的行数为 1 行)                                                       
------------------------------------------------------ 
2009-02-16 00:00:00.000(所影响的行数为 1 行)
可见可以将一个日期保存为数字,用时进行转换就变会日期的格式了。
但是我如果保存时间呢?我想用一个小数存贮时间,我不知如何实现,谢谢。

解决方案 »

  1.   

    select datediff(dd,cast('' as datetime),getdate())
    39858
      

  2.   

    select datediff(day,0,getdate())等价于select datediff(day,'1900-01-01',getdate())
      

  3.   

    为什么非要小数类型?最后转换还是得转回int的
      

  4.   

    好象几位还是没明白,
    我的想法是用两个字段组合在一起保存日期和时间。
    其中一个字段只存日期(用int型),另一个字段保存时间(用numeric型)
      

  5.   


    select cast(left(
                  cast((datename(hh,(getdate()))*60+
                        datename(mi,getdate())) as numeric(10,4))/(24*60),12)as numeric(10,4)) 
           as time 
      

  6.   


    select cast(left(
                  cast((datename(hh,(getdate()))*60+
                        datename(mi,getdate())) as numeric(10,4))/(24*60),12)as numeric(10,4)) 
           as time 
      

  7.   


    --将当前日期转成numeric型
    select cast(getdate() as numeric(18,3))--将当前日期保存到int型中
    select cast(datediff(day,0,getdate()) as int)--将当前时间保存到numeric型中
    select cast(cast(datediff(millisecond,0,convert(char(12),getdate(),114)) as numeric(18,3))/24/60/1000/60 as numeric(18,3))