How to convert Date-time values in SAS into TSQL

2019-09-11 14:47发布

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] 

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

1条回答
来,给爷笑一个
2楼-- · 2019-09-11 15:05

You said

Time values represent the number of seconds since midnight

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] 
查看更多
登录 后发表回答