SQL is greater, equal, and less than less

I want to create a query like the one below. But I'm not sure how to encode it correctly, I want it to return all orders within 1 hour from StartTime. Here is what I came up with:

SELECT BookingId, StartTime FROM Booking WHERE StartTime <=> 1.00 

Is it possible? or is there a way around it?

Everything that was found on the Internet was not about using more, equal, and less than everything in one request.

+4
source share
4 answers

Suppose you are using sql server:

 WHERE StartTime BETWEEN DATEADD(HOUR, -1, GetDate()) AND DATEADD(HOUR, 1, GetDate()) 
+10
source

If the start time is a datetime type, you can use something like

 SELECT BookingId, StartTime FROM Booking WHERE StartTime >= '2012-03-08 00:00:00.000' AND StartTime <= '2012-03-08 01:00:00.000' 

Obviously, you would like to use your own values ​​for time, but this should give you everything within 1 hour, including both the upper and lower limits.

You can use the GETDATE () function to get the current current date.

+4
source

Something like this should work L

 SELECT BookingId, StartTime FROM Booking WHERE StartTime between dateadd(hour, -1, getdate()) and getdate() 
+2
source
 declare @starttime datetime = '2012-03-07 22:58:00' SELECT BookingId, StartTime FROM Booking WHERE ABS( DATEDIFF( minute, StartTime, @starttime ) ) <= 60 
+2
source

Source: https://habr.com/ru/post/1400301/


All Articles