Reputation: 3001
Is there a way to run a SELECT
query with a WHERE
condition that looks at just one component of a DATETIME
field? For example, I want to select all entries where the hour component = 20. So if I had three entries:
2014-03-15 20:05:32.000
2013-06-02 20:57:15.000
2014-03-15 00:57:32.000
I would want the query to select the first two entries, but not the third. Is that possible?
Upvotes: 0
Views: 24
Reputation: 898
You want to use datepart
:
SELECT *
FROM foo
WHERE DATEPART('hh', created) = 20;
Upvotes: 2