Reputation: 35
I have been using postgreSQL. My table has 3 columns date, time and userId. I have to find out records between the given date and time frame. Since date and time columns are different, 'BETWEEN' clause is not providing valid results
Upvotes: 0
Views: 1325
Reputation:
Combine the two columns into a single timestamp by adding the time to the date:
select *
from some_table
where date_column + time_column
between timestamp '2017-06-14 17:30:00' and timestamp '2017-06-19 08:26:00';
Note that this will not use an index on date_column
or time_column
. You would need to create an index on that expression. Or better: use a single column defined as timestamp
instead.
Upvotes: 2