SQLite Extract Month From Column

2019-06-07 15:34发布

问题:

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