0

Below is my code

Date currentDate = new Date();
DateFormat dateFormatCmp = new SimpleDateFormat("yyyy-MM-dd");

if(dateFormatCmp.format(currentDate).equals(dateFormatCmp.format(task.getExecutionDate())))
{
  //doSomething here
}

current date is having value - 2014-12-02 and task.getExecutionDate() is having value 2014-12-05

Even then it is entering into if condition. Date comparison is not done properly.

user2488578
  • 896
  • 4
  • 21
  • 40
  • 1
    Are you really sure? I think you should debug or at least log the result of `dateFormatCmp.format(task.getExecutionDate())`. – Luiggi Mendoza Dec 02 '14 at 15:16
  • Yes, the values that I have mentioned in the question are after debugging.. – user2488578 Dec 02 '14 at 15:22
  • 2
    Again: Are you **really** sure? String comparison is not broken. If this is done in multiple threads, then you would be better by logging the value of `dateFormatCmp.format(task.getExecutionDate())`, the name of the thread and some other info that helps you identify the `task` that gives you this issue. – Luiggi Mendoza Dec 02 '14 at 15:24
  • Try to execute this code http://pastebin.com/J5yYcRL5 to see what values you are actually processing. – Pshemo Dec 02 '14 at 15:38
  • In your real code do you happen to have a ';' behind the if that is not showing here? – fishinear Dec 02 '14 at 17:03

0 Answers0