K
K
kyurem_bog2019-04-22 09:03:42
Transact SQL
kyurem_bog, 2019-04-22 09:03:42

How to display data by time without affecting the date?

There is a field in the table with date data in it of this form 2019-04-21 22:58:25.437, I need to display data by time, let's say all that are more than 9 hours.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-04-22
@kyurem_bog

https://metanit.com/sql/sqlserver/8.3.php
You can take the date component - time (hour and minute) and compare them with the required ones.

SELECT * FROM table
WHERE DATEPART(hour, [date_field]) > 9

K
Konstantin Tsvetkov, 2019-04-23
@tsklab

Alexander 's decision is absolutely correct.
But if you need time , then there is a construction:

SELECT CAST( GETDATE() AS DATE), CAST( GETDATE() AS TIME)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question