SQLite从列中提取月份 [英] SQLite Extract Month From Column

查看:261
本文介绍了SQLite从列中提取月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据列,日期格式为 mm / dd / yyyy 。我想把这个转换为(SQLite使用)格式 yyyy-mm-dd 。如何实现这一点?

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

我已经尝试了substr,ltrim,rtrim(对于我的情况,这一切都没有)。

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

我的数据是动态的。

示例

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)

谢谢。

推荐答案

从日期提取特定日期元素的语法字段是使用strftime。
SELECT strftime('%m',Column_Name)AS月份这是您的第二个问题。为了重构日期数据,您可以使用(至少在JavaScript中)substr将日期分割出来,然后根据需要进行格式化。另请参阅这篇文章:从sqlite的DATETIME获取月份

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

这篇关于SQLite从列中提取月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆