Date Filter in java -
this question has answer here:
- how compare dates in java? 11 answers
i need filter date "from date" "to date" using "current date" filter.
here code use in java application:
string = "19/05/1991"; string cmp = "23/05/1991"; string = "23/12/2015"; if (from.compareto(cmp) <= 0 && to.compareto(cmp) >= 0) { system.out.println("date lies between , date"); }
is code correct?
you should this:
string = "19/05/1991"; string cmp = "23/05/1991"; string = "23/12/2015"; dateformat format = new simpledateformat("dd/mm/yyyy"); date date1 = format.parse(from); date date2 = format.parse(cmp); date date3 = format.parse(to); if(date1.before(date2) && date3.after(date2)) { system.out.println("date lies between , date"); }
see date#after , date#before
Comments
Post a Comment