-2
 @GetMapping("/{dateFrom}/{dateTo}")
       public List<com.example.demo.attendance> getRange(@PathVariable("dateFrom")  String dateFrom,@PathVariable("dateTo") String dateTo) throws ParseException{
          Date date1= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(dateFrom);
          Date date2= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(dateTo);
          System.out.println(date1);
          System.out.println(date2);
           List<com.example.demo.attendance> att =  this.attRepo.findDateBetween(date1,date2);

           return att;
        }

here i am trying tho convert the date in the format (yyyy-MM-dd) to the format in which date is saved in mongodb to perform queries

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Rithvik
  • 1
  • 2
  • 1
    don't put screenshot write your original code in the question .. – Harshad Pansuriya Dec 09 '17 at 11:57
  • edited @Ironman – Rithvik Dec 09 '17 at 12:02
  • 1
    as looking your code..your not trying to save `Date` in database – Amol Raje Dec 09 '17 at 12:15
  • While it’s not 100 % clear to me what you are asking, I dare say similar questions have been asked and answered often before. Did you search? Always a good idea before asking. If you searched and found answers that weren’t sufficient for solving your issue, please explain in detail what it is you are still missing, and we can guide you much more precisely. – Ole V.V. Dec 09 '17 at 12:45
  • Possible duplicate of [Converting ISO 8601-compliant String to java.util.Date](https://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date) – Ole V.V. Dec 09 '17 at 12:45

1 Answers1

0

In my opinion date parameters should be rather passed as request parameters but anyway. Why don't you do this instead:

@GetMapping("/{dateFrom}/{dateTo}")
public List < com.example.demo.attendance > getRange(@PathVariable("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date fromDate, 
  @PathVariable("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) throws ParseException {
    System.out.println(date1);
    System.out.println(date2);
    List < com.example.demo.attendance > att = this.attRepo.findDateBetween(date1, date2);

    return att;
}

Currently MongoDB driver supports only java.util.Date I don't know which version of MongoDB Java Driver you use but here is the Documentation of the driver’s support for BSON document representations for 3.4. You can keep up-to-date in case something changes. Here to find the latest documentation for the MongoDB Java Driver

Alex P.
  • 3,073
  • 3
  • 22
  • 33