7

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

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
reyalino
  • 97
  • 1
  • 1
  • 4

3 Answers3

15

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
  • 451,927
  • 24
  • 239
  • 318
14

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

select DATE(my_field) from my_table;
Mayank Pandeyz
  • 24,624
  • 3
  • 35
  • 55
1

Try this way:

select date("Date") from yourTable
Vijunav Vastivch
  • 4,085
  • 1
  • 14
  • 29