13

I have date column on my postgres table as timestamp format i.e "2017-01-01 22:00:00". When I wrote in the queries

select date from table where date = '2017-01-01' it did not give me any result.

Should I always include the time information on those queries? Can I just put the yyyy-mm-dd only on my queries to search the date column?

regards

reyalino
  • 157
  • 1
  • 1
  • 5

3 Answers3

22

Cast to date:

select "date" from table where "date"::date = '2017-01-01'

Note that I enclosed references to the date column in double quotes, because date is a Postgres keyword. You should avoid naming your columns, tables, or schemas using keywords.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
18

Use date() function, it will extract date from datetime like:

select DATE(my_field) from my_table;
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
1

Try this way:

select date("Date") from yourTable
Vijunav Vastivch
  • 4,153
  • 1
  • 16
  • 30