Check date between two other dates spring data jpa

You should take a look the reference documentation. It’s well explained.

In your case, I think you cannot use between because you need to pass two parameters

Between – findByStartDateBetween … where x.startDate between ?1 and ?2

In your case take a look to use a combination of LessThan or LessThanEqual with GreaterThan or GreaterThanEqual

  • LessThan/LessThanEqual

LessThan – findByEndLessThan … where x.start< ?1

LessThanEqual findByEndLessThanEqual … where x.start <= ?1

  • GreaterThan/GreaterThanEqual

GreaterThan – findByStartGreaterThan … where x.end> ?1

GreaterThanEqual – findByStartGreaterThanEqual … where x.end>= ?1

You can use the operator And and Or to combine both.

Leave a Comment