如何从SQLite数据库中获取特定月份的数据

时间:2021-09-05 05:32:14

I saved my data In SQLite Database. I saved my date in database as DATETIME datatype.

我在SQLite数据库中保存了我的数据。我将日期保存在数据库中作为DATETIME数据类型。

I want to retrive only the data of specific month from my SQLite databse.

我想从我的SQLite数据库中只检索特定月份的数据。

I try the below query to retrive data, but it was not useful. It gives me data but it was not the specific month.

我尝试以下查询来检索数据,但它没用。它给了我数据,但不是具体的月份。

SELECT coulumn_name FROM table_name WHERE column_name Between "MM-DD-YYYY" AND "MM-DD-YYYY"

2 个解决方案

#1


7  

This is probably not optimal, but you could use:

这可能不是最佳的,但您可以使用:

select column_name from table_name where strftime('%Y-%m', column_name) = '2011-05';

#2


2  

Use a function retrieve only the month of the date

使用函数仅检索日期的月份

SELECT strftime('%m', date(column_name)) FROM table;

I believe this is the function, but I'm not so sure.

我相信这是功能,但我不太确定。

#1


7  

This is probably not optimal, but you could use:

这可能不是最佳的,但您可以使用:

select column_name from table_name where strftime('%Y-%m', column_name) = '2011-05';

#2


2  

Use a function retrieve only the month of the date

使用函数仅检索日期的月份

SELECT strftime('%m', date(column_name)) FROM table;

I believe this is the function, but I'm not so sure.

我相信这是功能,但我不太确定。