0

I'm trying to get the data of a document number in the last month but I'm not getting it. What did I do:

private DataIndicated getDataBetween(String numberDocument) {

        LocalDateTime start = LocalDate.now().atStartOfDay();
        LocalDateTime end = LocalDate.now().atTime(LocalTime.MAX);

        return repository.findByDocumentAndDataBetween(numberDocument, start, end);
    }

Repository:

DataIndicated findByDocumentAndDataBetween(String numberDocument, LocalDateTime start, LocalDateTime end);

Does anyone have an idea of ​​how to make this query taking only the data of the document number of the last month?

I'm using Java 8 and SpringBoot 2.5.8

Thanks!

devnan
  • 33
  • 1
  • 8
  • https://stackoverflow.com/questions/39784344/check-date-between-two-other-dates-spring-data-jpa – JCompetence Feb 04 '22 at 13:42
  • @SMA This answer was not useful because I need it to dynamically return the data of the last month passing only the document number as a parameter. – devnan Feb 04 '22 at 13:59
  • Are you sure that the time you are passing as start and end is correct? End time should be the current time and start time should be in the past. If this way you are passing your time and not getting the data, probably need more input from your end. – Govil Kumar Feb 04 '22 at 14:36

1 Answers1

0

That should work if the Data variable in the entity of type LocalDateTime and you want to get last month's data, You can use in the repository:

List<DataIndicated> findAllByDocumentAndDataAfter(String numberDocument, LocalDateTime localDateTime);

And pass this localDateTime to the repository as a parameter:

LocalDateTime localDateTime = LocalDateTime.now().minusMonths(1);