Home > Enterprise >  How to get all rows where the timestamp hours are between specific hours with Presto SQL?
How to get all rows where the timestamp hours are between specific hours with Presto SQL?

Time:10-25

I have a table and I want to retrieve all rows for a date column like 2022-10-24 21:03:00 where the hours for every date are between 21:00:00 and 22:00:00.

What would the SQL for this?

CodePudding user response:

Extract the hour from the timestamp and use that:

select *
from mytable
where extract(hour from timestamp_column) = 21;

CodePudding user response:

You can use hour function:

select *
from mytable
where hour(date_time) = 21;

If you need a particular day then use date_trunc:

select *
from mytable
where date_trunc('hour', date_time) = timestamp '2022-10-24 21:00:00';
  • Related