'How to filter data by date and month only in room database and ignoring year
@Query("Select * From Mstudent where (strftime('%d%m',dob)) = :todayDate order by (strftime('%d%m',dob))")
List<Mstudent> getStudentByBirthDate(Date todayDate);
this is what I have done but this is giving me an error because the query is not right. can we filter by date and month only and ignoring year?
Solution 1:[1]
Try this query (in case you use TypeConvertor Date
to Long
):
@Query("Select * From Mstudent where strftime('%d%m',datetime(dob/1000, 'unixepoch'))= strftime('%d%m',datetime(:todayDate/1000, 'unixepoch')) order by strftime('%d%m',dob)")
List<Mstudent> getStudentByBirthDate(Date todayDate);
Solution 2:[2]
This Query Maybe you are finding
"Select * From Mstudent where strftime('%d%m',datetime(dob/1000, 'unixepoch'))= strftime('%d%m',datetime(:todayDate/1000, 'unixepoch'))"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sergiy tikhonov |
Solution 2 | Rahul Tala |