get dates data from room database
i have created task db class as below
@ColumnInfo(name = "task_start_date") var taskStartDate: Date?,
@ColumnInfo(name = "task_end_date") var taskEndDate: Date?,
@ColumnInfo(name = "task_never_end") var taskNeverEnd: Boolean?
@PrimaryKey
var tid: Long?,
@ColumnInfo(name = "task_title") var TaskTitle: String?
I do insert data with below function
fun getTodayDate(): Date {
val calendar = Calendar.getInstance()
return GregorianCalendar(
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DATE),
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
calendar.get(Calendar.SECOND)
).time
}
fetching data with below codes and params todayDate = above functio getTodayDate()
@Query("select * from task where task_start_date =:todayDate ")
fun getTodayTask(todayDate: Date): List<Task>
with above implementation I m getting 0 result I assume room is converting date to long and stores and also compare with long value so this thing never gonna match so can u please help me out how to get task that only matched dates not time
example
I have inserted data for 11-09-2022 12:00:00 PM,11-09-2022 1:00:00 PM,11-09-2022 2:00:00 PM,11-09-2022 3:00:00 PM,11-09-2022 4:00:00 PM in the form of Date object not string. now I want to fetch all task that match only date like 11-09-2022 not time
Converter
class TimestampConverter {
@TypeConverter
fun fromTimestamp(value: Long?): Date? {
return value?.let { Date(it) }
}
@TypeConverter
fun dateToTimestamp(date: Date?): Long? {
return date?.time
}}
