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?

Était-ce utile?

La 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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top