mameesh
mameesh

Reputation: 3761

How do I say where time is less that a certain hour/minute

I have the following where clause in my query:

(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:

--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?

Upvotes: 1

Views: 78

Answers (1)

JNK
JNK

Reputation: 65157

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

Upvotes: 3

Related Questions