Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7571

Selecting records from a particular time in SQL

I want to select records from SQL server table 'employeelogdetails' which has field 'logintime' (which registers time in GMT when employee swipes the access card while entering or leaving office) which is datetime datetype. Now I want to select records say from yesterday 17 October 2012, 14:00 GMT

SELECT * FROM EMPLOYEELOGDETAILS WHERE LOGINTIME > ' ..........' LOGINTIME DESC

Don't know how to go forward guys, have been trying this for a while

Help me out

Upvotes: 0

Views: 1099

Answers (4)

techBeginner
techBeginner

Reputation: 3850

 SELECT * FROM EMPLOYEELOGDETAILS WHERE 
   LOGINTIME > CONVERT(DateTime,'2012/10/17 14:00:00') ORDER BY LOGINTIME DESC 

Upvotes: 0

Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7571

This can also work this way:

SELECT * FROM EmployeeLogDetails  
WHERE LoginTime BETWEEN ('20121017 9:00:00.000' AND '20121018 3:37:00.000') 
ORDER BY LoginTime DESC;

Thank you all for the responses

Upvotes: 0

Adam Wenger
Adam Wenger

Reputation: 17540

The following query will give you records from the 17th after 14:00 for the rest of the day. I'm not certain what time window you are looking for though, so this may need slight adjustment.

SELECT *
FROM EmployeeLogDetails AS eld
WHERE eld.LoginTime > '2012-10-17 14:00:00'
   AND eld.LoginTime < '2012-10-18'
ORDER BY eld.LoginTime DESC;

Upvotes: 1

Vijaychandar
Vijaychandar

Reputation: 714

Use this query:

select * from EmployeeLogDetails where LoginTime between '17/10/2012' and Now();

Upvotes: 0

Related Questions