如何将datetime转换为时间并从两个不同的列中选择记录?

时间:2013-10-14 13:25:07

标签: sql sql-server

我想在sql server中将日期时间转换为24小时,我想根据时间选择记录......!

我的表格如下

id        1                     2                 3
starttime 12:00:00.0000000   01:00:00.0000000 12:00:00.0000000
EndTime   23:59:59.0000000   13:59:59.0000000 23:59:59.0000000

startTime : 14/10/2013 01:02 AM and end time 14/10/2013 11:02 PM.时应显示记录 id 2& 3 我的SQL查询如下

SELECT * FROM  TableTimes 
WHERE StartTime >= CONVERT(char(8),CONVERT(time,'14/10/2013 01:02 AM',103), 108) 
AND [EndTime]<= CONVERT(char(8),CONVERT(time,'14/10/2013 11:02 PM',103), 108)

1 个答案:

答案 0 :(得分:0)

你试过吗

SELECT * FROM  TableTimes 
HAVING StartTime >= CONVERT(char(8),CONVERT(time,'14/10/2013 01:02 AM',103), 108) 
AND [EndTime]<= CONVERT(char(8),CONVERT(time,'14/10/2013 11:02 PM',103), 108)