Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 59
  • Last Modified:

Need help with a query

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
RadhaKrishnaKiJaya
Asked:
RadhaKrishnaKiJaya
1 Solution
 
Randy PooleCommented:
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
 
RadhaKrishnaKiJayaAuthor Commented:
Thanks a lot.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Curiosity overwhelms me why you would want to convert a date to a varchar in order to perform a math expression...
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now