I am in need of experts' help here. I have a column "Actual_Date" of data type timestamp
. It is in the format:
yyyy - mm - dd 00:00:00
I want to convert the column into the format:
mm - dd - yyyy
How can I convert the date?
I am in need of experts' help here. I have a column "Actual_Date" of data type timestamp
. It is in the format:
yyyy - mm - dd 00:00:00
I want to convert the column into the format:
mm - dd - yyyy
How can I convert the date?
The exact data type matters. If you have a timestamp
column (timestamp without time zone
) and want the date part as date
, just cast:
SELECT my_timestamp::date;
You can do the same with timestamptz
(timestamp with time zone
), the resulting date depends on the time zone setting of your current session, though. The current "date" depends on where in the world you ask ...
Or you can use to_char()
like a_horse provided, to get a text
as result.
If it's just a matter of how date and timestamp are displayed, look at the datestyle
setting:
To get reliable text
representation, independent of settings, to_char()
is the safe bet.
You just need to format it the way you want using to_char()
select to_char("Actual_Date", 'mm-dd-yyyy')
from the_table;
More details in the manual:
https://www.postgresql.org/docs/current/static/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE