How do I reference sqlite db column to use in update statement

两盒软妹~` 提交于 2020-03-25 07:41:13

问题


I am trying to update a datetime column in an android sqlite db to use international date format (yyyy-mm-dd) instead of the current format (mm/dd/yyyy). I want to use the sqlite date() function to reformat the current value of the column. I thought it would be as simple as the following:

update tblename set thedate = date(thedate)

but the above does not work.

How would i write the sql statement to accomplish this?

thanks patrick


回答1:


DATE() doesn't understand your old date format.

The following should work:

UPDATE tblname SET thedate = substr(thedate, 7, 4) || '-' || substr(thedate, 1, 2) || '-' || substr(thedate, 4, 2);



来源:https://stackoverflow.com/questions/2795043/how-do-i-reference-sqlite-db-column-to-use-in-update-statement

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