Solved

Need help with a query

Posted on 2016-09-07
3
55 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 66

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

623 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