I want to print out a result provided that the dates match, depending on either month or the specific day.
At the moment, I can only get it to print out a correct message if the dates fully match; the first date is generated from user input, so if that changes, I'd like to compare it to the second date to see if the year and month are still the same. If they are the same, I'd like to print out "Correct" as well.
String date1 = "2018-02-04";
String date2 = "2018-02-04";
if(date1.trim().equals(date2.trim())){
System.out.println("Correct");
}
ADDED/UPDATED FOR CLARIFICATION:
while (m.hasNextLine())
{
carReg = m.next();
carModel = m.next();
carType = m.next();
vehicleSize = m.next();
carColour = m.next();
carMileage = m.next();
carAccidentHistory = m.next();
carTransmissionType = x.next();
carCost = m.next();
DateArrived = m.next();
DateSold = m.next();
m.nextLine();
if(userDate.trim().equals(DateSold.trim())){
System.out.println("Correct output.");
}
// This if condition works fine, but I'm attempting to match the date the user inputs to any date that is being scanned, provided the year and month match.