sqlite change date format of every cell in column

做~自己de王妃 提交于 2019-12-20 05:11:31

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/23125390/sqlite-change-date-format-of-every-cell-in-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!