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?
The TO_DATE function in PostgreSQL is used to converting strings into dates. Its syntax is TO_DATE(text, text) and the return type is date. The TO_TIMESTAMP function converts string data into timestamps with timezone. Its syntax is to_timestamp(text, text) .
In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column. (In our example, we use a column of the timestamp data type.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With