DATETIME check for hours

0

I need to do a search by hours, that is to say that I see a specific field filtered by X hour

    
asked by R.Priego 14.10.2016 в 12:27
source

5 answers

0

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;
    
answered by 14.10.2016 / 16:32
source
1

In Oracle Databases you can use:

SELECT EXTRACT(HOUR FROM SYSDATE) FROM MiTabla;

Taken from: link

    
answered by 14.10.2016 в 12:48
1

This can help you:

link

SELECT HOUR(ShoppingDate), COUNT(*) FROM YourTable
GROUP BY HOUR(ShoppingDate)

Originally published by @JonSkeet

    
answered by 14.10.2016 в 13:20
0

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.

    
answered by 14.10.2016 в 16:42
0

Try this, to get it back in the format yyyy-mm-dd hh: mm: ss (24h)     SELECT convert (varchar (25), getdate (), 120)

    
answered by 14.10.2016 в 17:29