Jaspreet Kaur
Jaspreet Kaur

Reputation: 1720

How to fetch Records from Sqlite based on From date and to date

I am trying to fetch the records from SQLite database based on from date and to date. For example: Fetch the Records who has birthDay between 2 Feb to 5 March. The problem is that the DOB column also store birthday year of person and I don't want to consider the year to fetch records. The Format to store DOB in the database is DD-mm-YYYY (02-02-1990).

Upvotes: 0

Views: 62

Answers (2)

Jaspreet Kaur
Jaspreet Kaur

Reputation: 1720

//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" 

Upvotes: 1

vinod
vinod

Reputation: 1126

Create other 2 columns, which store only Day and Month. then the Query example is

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

Upvotes: 1

Related Questions