Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get records after a certain time using SQL datetime field

Tags:

If I have a datetime field, how do I get just records created later than a certain time, ignoring the date altogether?

It's a logging table, it tells when people are connecting and doing something in our application. I want to find out how often people are on later than 5pm.

(Sorry - it is SQL Server. But this could be useful for other people for other databases)

like image 865
thursdaysgeek Avatar asked Oct 06 '08 23:10

thursdaysgeek


People also ask

How do I query a timestamp in SQL?

To get a day of week from a timestamp, use the DAYOFWEEK() function: -- returns 1-7 (integer), where 1 is Sunday and 7 is Saturday SELECT dayofweek('2018-12-12'); -- returns the string day name like Monday, Tuesday, etc SELECT dayname(now()); To convert a timestamp to a unix timestamp (integer seconds):


1 Answers

For SQL Server:

select * from myTable where datepart(hh, myDateField) > 17

See http://msdn.microsoft.com/en-us/library/aa258265(SQL.80).aspx.

like image 159
Luke Bennett Avatar answered Sep 16 '22 19:09

Luke Bennett