如何将SAS中的日期时间值转换为TSQL [英] How to convert Date-time values in SAS into TSQL

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

问题描述

我从SAS服务器读取一些日期时间值,SAS日期值的存储方式是数字变量。日期值表示自1960年1月1日起的天数。时间值表示自午夜以来的秒数。日期时间值表示自1960年1月1日以来的秒数。我可以读取日期值,我得到正确的转换,但我的问题是我无法转换时间值。这是我如何转换日期值

I am reading some date-time values from SAS server and the way SAS date values are stored is in numeric variables. Date values represent the number of days since January 1, 1960. Time values represent the number of seconds since midnight. Datetime values represent the number of seconds since January 1, 1960. I am able to read the date values and i am getting the correct conversion but my problem is that i can't convert the time values. here is how i am converting the date values

DATEADD(DAY, [SC_ADMIT_DT],'19600101')AS [SC_ADMIT_DT] 

这将给我2009-12-15,没关系。但是我有另一列ADMT_TIME,存储在SAS中的时间值是这样的:29520,我想转换它来显示正确的日期时间值。我甚至不知道这是日期时间戳还是只是时间。谢谢

this will give me 2009-12-15 and that is fine. But i have another column ADMT_TIME, the time value that is stored in the SAS is somthing like this: 29520 and i want to convert it to show the proper date time value. I am not even sure if this is date time-stamp or just time only. Thanks

推荐答案

你说


时间值代表自午夜以来的秒数

Time values represent the number of seconds since midnight

由于29520/3600是8.2小时,即8:12 AM,似乎是正确的。那么为什么不简单地添加那些秒?

And since 29520 / 3600 is 8.2 hours, i.e. 8:12AM, that seems correct. So why not simply add those seconds?

DATEADD(SECOND, [ADMT_TIME], DATEADD(DAY, [SC_ADMIT_DT], '19600101')) AS [SC_ADMIT_DT] 

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

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