我怎么说时间少于某小时/分钟

时间:2021-04-03 16:27:48

I have the following where clause in my query:

我的查询中有以下where子句:

(DATEPART(hh,[AuditInsertTimestamp]) >= 17
        OR DATEPART(hh,[AuditInsertTimestamp]) <= 6)

So Audit Insert Timestamp is greater or equal to 5PM and Audit Insert Timestamp is less than or equal to 6AM. Where really what I want is Audit Insert Timestamp is less than or equal to 5:30AM. I was thinking about adding:

因此,审计插入时间戳大于或等于5PM,审计插入时间戳小于或等于6AM。我真正想要的是审计插入时间戳小于或等于5:30 AM。我在想添加:

--AND DATEPART(mi,[AuditInsertTimestamp]) < 30)

But that would only give me times with minutes below 30 correct? What would be the best way to get <= 5:30AM?

但那只会给我30分钟以下的时间正确吗?什么是最好的方式<= 5:30 AM?

1 个解决方案

#1


3  

(
 DATEPART(hh,[AuditInsertTimestamp]) >= 17
 OR DATEPART(hh,[AuditInsertTimestamp]) < 5
 OR (DATEPART(hh,[AuditInsertTimestamp]) = 5
     AND
     DATEPART(minute,[AuditInsertTimestamp]) <= 30)
)

#1


3  

(
 DATEPART(hh,[AuditInsertTimestamp]) >= 17
 OR DATEPART(hh,[AuditInsertTimestamp]) < 5
 OR (DATEPART(hh,[AuditInsertTimestamp]) = 5
     AND
     DATEPART(minute,[AuditInsertTimestamp]) <= 30)
)