How to filter data by date and month only in room database and ignoring year

Viewed 494
    @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?

2 Answers

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);

This Query Maybe you are finding

"Select * From Mstudent where strftime('%d%m',datetime(dob/1000, 'unixepoch'))= strftime('%d%m',datetime(:todayDate/1000, 'unixepoch'))"
Related