Home > front end >  How to select data where id and date range timestamp in postgres
How to select data where id and date range timestamp in postgres

Time:09-01

I have a problem to make a query for view data in postgresql. I want to view data with 2 condition :

  1. where employeeId
  2. and between daterange

Heres my Query:

Select * 
from employee 
where employeeId = 3 
  and date(created_at) = between '2022-08-29' and '2022-08-31'

I have run that query but show error:

Reason:

SQL Error [42601]: ERROR: syntax error at or near "date" Position: 1`

The type data of column created_at is timestamp. My questions is: What is correct query for view data from that conditions?

CodePudding user response:

Remove the = operator from your query, the BETWEEN does not require the =

Select * from employee where employeeId = 3 and date(created_at)  between '2022-08-29' and '2022-08-31' 

CodePudding user response:

You can use arithmetic operation

Select * 
from employee 
where employeeId = 3 
  and created_at>='2022-08-29' 
  and created_at< '2022-09-01'
  • Related