Hello good people of the world,
I seem to be having a problem with how to make comparisons of dates using the Gregorian calendar objects. i want to find out if there is a way in which i can achieve it.the idea is make comparisons between the current date with a date that wud be produced within a 2 week time frame.To achieve this i set back the system time.but so far i've failed to make the comaprison and am getting compilation errors.Where am i going wrong?the code is below.

import java.util.*;
import java.text.*;
class Today {
   public static void main(String[] args) 
   {
      String day2 = null;
      String day1 = null;
      String day3 = null;
      day2 = Later(day2);
      day1 = Today(day1);
      day3 = Then(day3);
      
      if(day1.equals(day1))
      {
        System.out.println("This the same date "+ day1);
        
      }
      else
      if (day1.after(day2) && day2.before(day3))
      {
        System.out.println("This date is after " + day2 + " days");
      }
      else
      {
        System.out.println("This date comes after " + day3 + " days");
      }
   }
   public static String Today(String day1)
   {
        GregorianCalendar today = new GregorianCalendar();
        Date t = today.getTime();
        DateFormat dft = DateFormat.getDateInstance();
        day1 = dft.format(t);
        return day1;
   }
   public static String Later(String day2)
   {
       GregorianCalendar thisday = new GregorianCalendar();
       thisday.add(GregorianCalendar.DATE,7);
       Date d = thisday.getTime();
       DateFormat df = DateFormat.getDateInstance();
       day2 = df.format(d);
       return day2;
   }
   public static String Then(String day3)
   {
       GregorianCalendar thisday = new GregorianCalendar();
       thisday.add(GregorianCalendar.DATE,14);
       Date d = thisday.getTime();
       DateFormat df = DateFormat.getDateInstance();
       day3 = df.format(d);
       return day3;
   }
}

(day1.after(day2) day1 and day2 are Strings. They don't have an after method:

The method after(String) is undefined for the type String

You should be able to figure that out.

I would suggest your methods to return the date object since it has these methods:

public static Date Later()
   {
       GregorianCalendar thisday = new GregorianCalendar();
       thisday.add(GregorianCalendar.DATE,7);
       Date d = thisday.getTime();
       return d;
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.