2017-04-08 57 views
0

我想從日期和時間的SQLite數據庫中獲取記錄。 例如:在2月2日到3月5日之間取得生日的記錄。 問題是,DOB列還存儲了人的生日年,我不想考慮年份來獲取記錄。 在數據庫中存儲DOB的格式是DD-mm-YYYY(02-02-1990)。如何從Sqlite獲取記錄基於From date和date

回答

1

創建其他2列,只存儲日和月。然後查詢的例子是

select * from table1 where day between 1 and 5 and month between 2 and 5 
+0

感謝,它是一個簡單的解決方案。 –

+0

如果日期相同,例如2月10日至6月10日,此查詢將不起作用。我已使用新答案中的查詢方式解決了此錯誤。 –

1
//Concatenate MonthDayFields and use between statement to fetch records 

// This Query will Fetch Records From 5 Oct to 5 Apr 

SELECT *,substr('00'||DOB_Month,-2,2) || substr('00'||DOB_Day, -2, 2) 
as 'myField' FROM Table1 
WHERE (myField BETWEEN "1005" AND "1231") OR (myField BETWEEN "0101" AND "0405") 


// This Query will Fetch Records From 5 Apr to 18 Oct 

SELECT *,substr('00'||DOB_Month,-2,2) || substr('00'||DOB_Day, -2, 2) 
as 'myField' FROM Table1 
WHERE myField between "0405" and "1018"