Question

I have a table with a large number of rows. One column contains dates in the format '%m/%d/%Y' and I want to change all of them to format '%Y-%m-%d'

the usual: update table set mydate = '6'

doesn't work I guess because the date is always changing. How would I do that in this case?

Was it helpful?

Solution

If the fields in the date string are properly padded with zeros, you can extract them as substrings:

UPDATE MyTable
SET MyDate = substr(MyDate, 7, 4) || '-' ||
             substr(MyDate, 1, 2) || '-' ||
             substr(MyDate, 4, 2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top