I have this model:
public class Event {
private String name;
private Date start;
private Date end;
}
and repository as
@Repository
public interface EventRepository extends JpaRepository<Event, Long> {
List<Event> findByEventTypeAccount(Account account);
}
What I want to do is, I will pass one date and need to check that date is between start
and end
eg(i will pass sept 30 as date and need to find all entries which have sept 30 between their start
and end
)
Something like findDateisBetweenStartAndEnd(Date date)
?
This question is related to
java
spring
spring-data-jpa
spring-repositories
I did use following solution to this:
findAllByStartDateLessThanEqualAndEndDateGreaterThanEqual(OffsetDateTime endDate, OffsetDateTime startDate);
Maybe you could try
List<Article> findAllByPublicationDate(Date publicationDate);
The detail could be checked in this article:
You can also write a custom query using @Query
@Query(value = "from EntityClassTable t where yourDate BETWEEN :startDate AND :endDate")
public List<EntityClassTable> getAllBetweenDates(@Param("startDate")Date startDate,@Param("endDate")Date endDate);
Source: Stackoverflow.com