I am trying to get a sum of figures by today's date. My approach is to use LocalDateTime formatted as below
yyyy-MM-dd HH:mm:ss
And The date I am picking from the server is of this format
2020-03-26 12:36:14.48947
Since the date variation keeps changing, my interest is to deal with this 2020-03-26 as both will exist from the formatted today's date and the date from the server
Here is the query I am using
"... AND p.regDate LIKE :todayDate..."
Here is the DateTimeFormertter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime today = null;
today = LocalDateTime.now();
System.out.println("here is today " + today);
With the approach above, I am getting an error. Please hw can I get todays date from the query
First of all, you need to a LocalDate
not LocalDateTime
to your query:
LocalDate today = LocalDate.now(); // current date "2020-03-26"
// or a custom LocalDate
LocalDate today = LocalDate.of(2020, Month.MARCH, 26);
And then, to get the date part from datetime in your databse, you can use :
"... AND DATE(p.regDate) = :todayDate..."
Where: DATE(p.regDate)
extract only the date part, the compare with =
not LIKE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.