Alina
Alina

Reputation: 369

select query with date in postgres sql

I want to select records from date with a specific date. The problem is there is timestamp in the date. For example:

Table name : books
record 1 : 09-04-2018 10:31:00
record 2 : 09-04-2018 10:32:00
record 3 : 09-04-2018 10:33:00
record 4 : 10-04-2018 17:54:00
record 5 : 10-04-2018 18:49:01

I want to retrieve all records on date 09-04-2018 irrespective of the time.

select * from books where bookdate >= '09-04-2018' => This query is returning me all 5 records instead of 3.

Upvotes: 1

Views: 103

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175596

I guess the problem is column/literal datatype:

select * from books where date::date >= '2018-04-09'::date;

" I try your query, still it returns all 5!"

Well, 2018-04-09 00:00:00 is smaller than all your 5 values.

Upvotes: 1

Related Questions