I need to do a search by hours, that is to say that I see a specific field filtered by X hour
You can also use the function:
DATEPART(PARTE, PARAMETRO)
PART may be the following constants DAY, HOUR, MINUTE, SECOND, YEAR, the parts that make up a datetime
PARAMETER is the data you want to get a part of.
The DATEPART function allows you to obtain a part of the TIME or DATE or DATETIME that you need to evaluate.
If for example you want to get all the records between 8 and 9 you can do something like this:
SELECT *
FROM tabla
WHERE DATEPART(HOUR, fechahora) BETWEEN 8 and 9;
This can help you:
SELECT HOUR(ShoppingDate), COUNT(*) FROM YourTable
GROUP BY HOUR(ShoppingDate)
Originally published by @JonSkeet
This can help you:
SELECT * FROM Tabla
WHERE FechaUltimaModificacion BETWEEN '20161010 10:00:00' AND '20161010 20:00:00'
Putting the hours parameters in the VARCHAR
of the date to search SQL interprets them perfectly.
Try this, to get it back in the format yyyy-mm-dd hh: mm: ss (24h) SELECT convert (varchar (25), getdate (), 120)