0

I want to compare user selected date with from date and to date. e.g.,

from date : 2017-25-07
to date   : 2017-31-07
Selected date : 2017-27-07

so now I want to check selected date is in the range between from date and to date.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • 1
    Googling your problem statement is the first thing that you should do. https://stackoverflow.com/questions/2592501/how-to-compare-dates-in-java – Nikhil Sahu Jul 25 '17 at 10:14
  • 1
    Welcome to Stack Overflow. Please see [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask), specifically the first section, *Search, and research*. What did your search and research bring up? – Ole V.V. Jul 25 '17 at 11:16

1 Answers1

1

you can compare three dates by below code

if(!fromDate.after(selectedDate) && !toDate.before(selectedDate)) {
  //fromDate <= selectedDate <= toDate
}
assylias
  • 321,522
  • 82
  • 660
  • 783
Sachin Gawai
  • 351
  • 1
  • 4
  • 15
  • yes it is working Thank you – Akash Bandal Jul 25 '17 at 10:22
  • Since a `java.util.Date` holds both a date and a time-of-day, some tricky surprises may come out when the date it the same and the time-of-day is different. It will be easier and a lot less errorprone with `LocalDate`. To use it on Android, you need the ThreeTenABP, see [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Jul 25 '17 at 11:19