Solved

Need help with a query

Posted on 2016-09-07
3
40 Views
Last Modified: 2016-09-07
Hi Experts,

I want to check for the time difference between 2 times, if it is less than 2 min.

select StdLogID,StdTimeIn from LOGINDETAILS  where userID = @UserID and TodaysDate =FORMAT(GetDate(),'MMddyyyy') and
DATEDIFF(MINUTE, convert(varchar,StdTimeIn,120),convert(varchar,CURRENT_TIMESTAMP,120) < 2
and StdTimeIn IS NOT NULL and StdTimeout IS NULL)

Thanks in advance.
0
Comment
Question by:RadhaKrishnaKiJaya
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
Comment Utility
Assuming StdTimeIn is a date field
select StdLogID,StdTimeIn from LOGINDETAILS  where userID = @UserID and DATEDIFF(SECOND, StdTimeIn,GetDate()) < 120
and StdTimeIn IS NOT NULL and StdTimeout IS NULL

Open in new window

0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
Comment Utility
Thanks a lot.
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Curiosity overwhelms me why you would want to convert a date to a varchar in order to perform a math expression...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now