Reputation: 91959
I have a PostgreSQL timestamp as
2009-12-22 11:01:46
I need to change this to date as
2009-12-22
So that I can compare the dates in postgreSQL
How can I achieve this transformation?
Upvotes: 28
Views: 64749
Reputation: 1505
SELECT [timestamp column] ::date;
Along in select query you can search on the basis of date
WHERE [timestamp column] :: date = '2022-05-30'
Upvotes: 0
Reputation: 38189
You can either use one of the Postgres date functions, such as date_trunc, or you could just cast it, like this:
SELECT timestamp '2009-12-22 11:01:46'::date
>>> 2009-12-22
Upvotes: 12
Reputation: 19222
Cast it to date
.
SELECT yourtimestamp::date;
If you need to extract other kinds of stuff, you might want to use EXTRACT or date_trunc
Both links are to the same page, were you'll find more date/time-related functions.
Upvotes: 65