First I know this is bad way to compare dates but I don't understand how to evaluate a strings to include the data between 2 values. For example in this code how would I list not only transactions that occurred on tdate 1 and 2 but also the transactions that fell between them.
tdate information is set up like 11/07/2013
System.out.println("Start Date: ");
tdate = in.next();
System.out.println("End Date: ");
tdate2 = in.next();
transactionSet trr = new transactionSet();
for(int idx = 0; idx < ts.getNumTrans(); idx++){
t = ts.retrieve(idx);
if (t.getTdate().equals(tdate) || t.getTdate().equals(tdate2)){
trr.insert(t);
}
}
SimpleDateFormat format = new SimpleDateFormat("d/M/yyyy"); // If this is the right format
Date first = format.parse(tdate);
Date second = format.parse(tdate2);
Date toCheck = format.parse(someDate);
if (toCheck.after(first) && toCheck.before(second)){
// ...
}
You might want to do this in a try/catch block, in case the dates that are input are not formatted correctly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.