How to convert the “detailDate” attribute into Date or LocalDate datatype if the “detailDate” attribute is String datatype in database? Beacause I want to solve a condition which is display the most updated “Odometer” value based on the “masterList” and “detailDate”. Reminder: This code is in Jmix 2.0. I show a code in java:
" List previousFuelDetails = dataManager.load(FuelDetails2.class)
.query("select e from FuelDetails2 e " +
"where e.masterList = :masterList " +
"and e.detailDate < :detailDate " +
“order by e.detailDate desc, e.time desc”)
.parameter(“masterList”, selectedMasterList)
.parameter(“detailDate”, selectedDetailDate)
.list();
if (!previousFuelDetails.isEmpty()) {
FuelDetails2 lastFuelDetailBeforeSelectedDate = previousFuelDetails.get(0);
lastodometerField.setValue(String.valueOf(lastFuelDetailBeforeSelectedDate.getOdometer()));
} else {
// Handle the case where no data exists for the selected date or previous dates
lastodometerField.setValue(“0”);
} "
I also use “Cast” to convert it into Datedatatype but it gives an error. Such this:
"List<FuelDetails2> fuelDetailsList = dataManager.load(FuelDetails2.class)
.query("select e from FuelDetails2 e " +
"where e.driverId = :driver " +
"and e.masterList = :masterList " +
"and (CAST(e.detailDate AS date) < :selectedDate or (CAST(e.detailDate AS date) = :selectedDate and e.time <= :selectedTime))")
.parameter("driver", selectedDriver)
.parameter("masterList", selectedMasterList)
.parameter("selectedDate", selectedDate, TemporalType.DATE) // Use TemporalType.DATE for date-only values
.parameter("selectedTime", selectedTime)
.list();"