问题
ReportView
I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo.
I've tried,
(1)
List list = session.createQuery("from ReportView where date between :stDate and :edDate")
.setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault()))))
.setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault()))))
.list();
(2)
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date frmDate = format.parse(tDateFrom.getValue().toString());
Date enDate = format.parse(tDateTo.getValue().toString());
list = session.createQuery("from ReportView where date between :stDate and :edDate")
.setTimestamp("stDate", frmDate)
.setTimestamp("edDate", enDate)
.list();
Both methods are not returning any row.
java.text.ParseException: Unparseable date: "2020-02-03"
at java.text.DateFormat.parse(DateFormat.java:366)
I've tried to fire query as mentioned in answer of this question : mysql select query where date = ... not returning data
But this query works in mySQL, not in HQL. How to use between clause for dates in HQL?
来源:https://stackoverflow.com/questions/60182463/hql-query-to-select-data-between-two-dates-not-returning-any-record