SQLite Extract Month From Column

家住魔仙堡 提交于 2019-12-23 01:21:47

问题


I have a column of data with this date format mm/dd/yyyy. I would like to covert to this to the format yyyy-mm-dd for (SQLite usage). How could I achieve this?

UPDATE Table_Name 
SET Column_Name = 'yyyy-mm-dd' format

I have tried substr, ltrim, rtrim (None of this work for my case).

My data are dynamic.

Sample

Column_Name
6/1/2004
06/25/2004
7/1/2003
6/1/2004
6/1/2004
09/19/2003
09/30/2003
09/30/2003
09/30/2003
09/30/2003

The Goal: Extract only month from this Column (Without displaying unnecessary stuff)

Thank you.


回答1:


The syntax for extracting a specific date element from a date field is to use strftime. SELECT strftime('%m', Column_Name) AS month which is your second question. For reconstituting the date data you could use (at least in JavaScript) substr to split the date out then format it as you require. Also see this post:Get month from DATETIME in sqlite



来源:https://stackoverflow.com/questions/11046570/sqlite-extract-month-from-column

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