sqlserver 日期时间 datetime 转成纯数字,
有这样的需求的应该比较多
正常思维
用convert转换成yyyy-mm-dd hh:mm:ss.nnn
select convert(varchar(24),getdate(),121)
然后把字符全部replace掉就ok了
我下面的函数是用数学计算,合计出数字类型numeric然后返回
秒是14位,毫秒是17位,int存不下 只能用 numeric
首先计算出年月日串 : @date
@date= 10000*年+100*月+日
时间串:@time
@time=10000000 * 小时 + 100000*分钟 + 1000*秒 + 毫秒
然后合计起来 :@date*1000000000 + @time
具体代码:
if exists(select * from sysobjects where name = 'f_get_datetime_ms' and type = 'FN')
drop function f_get_