Sqlite:将日期转换为月中的日期编号

时间:2013-03-20 11:48:08

标签: sqlite date

这是我的问题:我在sqlite数据库中有一些约会。我想做的是以下几点:

SELECT dates FROM Table1 WHERE dates > date('now','-1 month');

结果是:

2013-02-21 12:04:22
2013-02-28 12:04:22
2013-02-01 12:04:22

如何将这些日期转换为以下内容:

2013-02-21 12:04:22 become 2 (day 2 of the month)
2013-02-28 12:04:22 become 9 (day 9 of the month)
2013-03-01 12:04:22 become 10(day 10 of the month)

提前谢谢

2 个答案:

答案 0 :(得分:3)

尝试

select julianday(dates) - julianday(date('now','-1 month')) + 1
from table1
where dates > date('now','-1 month')

答案 1 :(得分:0)

select cast((julianday(dates) - julianday(date('now','-1 month')) + 1)as int)
from table1
where dates > date('now','-1 month')

只保留整数部分:)非常感谢AnatolyS