2013-03-20 91 views
1

這是我的問題:我在我的sqlite數據庫中有一些日期。我想要做的是以下情況: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) 

預先感謝您

+0

在哪裏,這些數字2,9,10從何而來?我看不出與日期有關。 – 2013-03-20 12:07:05

+0

現在(2013年3月20日) - 1個月==> 20/02/2013 在此期間(2013年2月20日至2013年3月20日)2013-02-21第二天對應於此期間(第2天),2013-02-28這一期間的第9天的對應,... – user2121458 2013-03-20 12:27:41

回答

3

嘗試

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

這樣,第一次日期(2013-02-21 12:04:22)變成2,50303!幾乎完美:)我怎麼能只保留整數部分(保持2並放下0,50303)? – user2121458 2013-03-20 17:04:31

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

只保留整數部分:)感謝很多AnatolyS

相關問題