Solved

Need help with a query

Posted on 2016-09-07
3
49 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
ID: 41788256
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
ID: 41788300
Thanks a lot.
0
 
LVL 65

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

828 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