如何根据开始日期和结束日期从 Sqlite 获取记录



我正在尝试根据从日期和日期从SQLite数据库中获取记录。例如:获取出生日介于 2 月 2 日至 3 月 5 日之间的记录。问题是 DOB 列还存储人的生日年份,我不想考虑获取记录的年份。在数据库中存储 DOB 的格式是 DD-mm-YYYY (02-02-1990(。

创建其他 2 列,仅存储日和月。 则查询示例为

select * from table1 where day between  1 and 5 and month between 2 and 5
//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" 

最新更新