Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find data from MySQL by month using JPA and java.time.LocalDate date format?

I creating an application, for that I need to find data by month using JPA and java.time.LocalDate. So, is it possible to retrieve data by month from mysql?

Thanks in advance for help.

like image 226
Kamlesh Samrit Avatar asked Dec 17 '25 21:12

Kamlesh Samrit


1 Answers

Its better to use the between keyword, it makes things allot shorter.

List<Object> findByCreatedateBetween(LocalDate start,LocalDate end);

Also if you want to use the LocalDate or LocalDateTime objects with Spring Data you should use the converter class Jsr310JpaConverters or else the documents will be stored as Blobs instead of Dates (which is bad for portability of the database). Please see this tutorial on how to implement the Converter.

https://www.mkyong.com/spring-boot/spring-boot-spring-data-jpa-java-8-date-and-time-jsr310/

like image 169
Maurice Avatar answered Dec 21 '25 01:12

Maurice