将 bigint 转换为日期时间 [英] Convert bigint to datetime

查看:234
本文介绍了将 bigint 转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个值从 bigint 转换为 datetime.

I want to convert a value from bigint to datetime.

例如,我正在阅读 teamcity 服务器HISTORY 表.在字段 build_start_time_server 上,我在一条记录 1283174502729 上有这个值.

For example, I'm reading the HISTORY table of teamcity server. On the field build_start_time_server, I have this value on one record 1283174502729.

如何将其转换为日期时间值?

How can I convert it to a datetime value?

推荐答案

这对您有用吗?它目前在 SQL Server 2005 上返回 30-8-2010 13:21:42:

Does this work for you? It returns 30-8-2010 13:21:42 at the moment on SQL Server 2005:

select dateadd(s, convert(bigint, 1283174502729) / 1000, convert(datetime, '1-1-1970 00:00:00'))

我除以 1000 是因为 dateadd 函数不能处理这么大的数字.所以你确实失去了一点精度,但使用起来要简单得多.

I've divided by 1000 because the dateadd function won't work with a number that large. So you do lose a little precision, but it is much simpler to use.

这篇关于将 bigint 转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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