Solved

Need help with a query

Posted on 2016-09-07
3
44 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.

919 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

14 Experts available now in Live!

Get 1:1 Help Now