Time format hhmm to hh:mm sql server 2005

点点圈 提交于 2019-12-13 18:12:20

问题


I want to find the time difference so i am trying to use DATEDIFF option. But the problem is i am having the time values in hhmm format(eg: 1715). So it showing out of range error. so i want to convert it to hh:mm format. How to convert hhmm to hh:mm format?


回答1:


Have you tried something like

DECLARE @TimeVal VARCHAR(4)
SELECT  @TimeVal = '1715'

select CONVERT(DATETIME,LEFT(@TimeVal,2) + ':' + RIGHT(@TimeVal,2),8)

Output

1900-01-01 17:15:00.000


来源:https://stackoverflow.com/questions/4130485/time-format-hhmm-to-hhmm-sql-server-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!