0

I have dates in the database with the format YYYYMMDD. But i would like to update them all to MM/DD/YYYYY.

How do i do that?

1 Answer 1

1

There is no format stored in the date/time data types. If you want an specific output format use the to_char function

select to_char(current_date, 'MM/DD/YYYY');

If the date column is text then first cast it to date to use the above function

select to_char(start_date::date, 'MM/DD/YYYY');
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. But the interface doesnt support/show the current format of the date (YYYYMMDD) in the database. So i will have to update the date in the database to mm/dd/yyyy. I tried to update using " Update <TableName> set start_date = to_char(current_date,'MM/DD/YYYY'); " .But it gives me the error " to_char(start_date, 'M... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts." Can you please assist?
@user What is the interface? Are you sure you are using Postgresql? Do select version()
@user Is the start_date text? Post the output of \d my_table
Yes. Start_Date is a varchar.It is postgres 8.4
BELOW WORKED. THANKS A LOT. select to_char(start_date::date, 'MM/DD/YYYY')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.