如何在T-SQL中将DateTime转换为精度高于天的数字? [英] How to convert DateTime to a number with a precision greater than days in T-SQL?

查看:157
本文介绍了如何在T-SQL中将DateTime转换为精度高于天的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两个查询转换为相同的号码

Both queries below translates to the same number

SELECT CONVERT(bigint,CONVERT(datetime,'2009-06-15 15:00:00'))
SELECT CAST(CONVERT(datetime,'2009-06-15 23:01:00') as bigint)

结果

39978
39978

只有天数不同,生成的数字才会有所不同。有没有办法将DateTime转换为更精确的数字,就像我们在.NET中使用.Ticks属性一样?

The generated number will be different only if the days are different. There is any way to convert the DateTime to a more precise number, as we do in .NET with the .Ticks property?

我需要至少一分钟的精度。 / p>

I need at least a minute precision.

推荐答案

嗯,我会这样做:

select datediff(minute,'1990-1-1',datetime)

其中'1990-1-1'是任意的基础日期时间。

where '1990-1-1' is an arbitrary base datetime.

这篇关于如何在T-SQL中将DateTime转换为精度高于天的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆