Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Comparing Date Strings

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Comparing Date Strings

    EDIT: Problem solved, feel free to remove thread.

    I have a linked list of assignments, each with a due date. Im looking to iterate through this list and for each assignment due date check if the date is after the first date, therefore finding which is due first.
    Below is what i have already. Im finding the first due date and formating the string into a date i can use. Then im going through the list of assignments formatting the due date and checking if it is after the dueDate string i have.

    Im getting an error message with if(checkDate.after(dueDate)) saying checkDate is a string not a date. i have tried using the date dateCheck as well but that also doesn't work

    public void dueDate()
       {
           SimpleDateFormat ValidFormat = new SimpleDateFormat("dd/MM/yyyy");
           ListIterator<Assignment> iterator = assignmentList.listIterator(0);
     
           String dueDate = iterator.next().getDueDate();
           try
           {
               Date date = ValidFormat.parse(dueDate);
               dueDate = ValidFormat.format(date);
           }
           catch(ParseException pe)
           {
               System.out.println("ParseException" + pe);
           }
     
           while(iterator.hasNext())
           {
              String checkDate = ValidFormat.format(iterator.next().getDueDate());
              try
              {
                  Date dateCheck = ValidFormat.parse(checkDate);
                  checkDate = ValidFormat.format(dateCheck);
              }
              catch(ParseException pe)
              {
                  System.out.println("ParseException" + pe);
              }
     
              if(checkDate.after(dueDate))
                  dueDate = checkDate;
     
           }
       }
    Last edited by wdh; April 26th, 2012 at 04:52 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Comparing Date Strings

    Im getting an error message
    Please post the full text of the error message.

     String checkDate =
    This defines checkDate as a String.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Comparing Date Strings

    You have not defined what the method checkDate.after is, thus we can only guess. My guess is the method signature defines a Date as a parameter, and you are trying to pass a String

  4. #4
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Comparing Date Strings

    EDIT: Sorry problem fixed.
    Last edited by wdh; April 26th, 2012 at 04:51 AM.

Similar Threads

  1. Comparing a character to an array of strings
    By Hashmeer169 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 4th, 2011, 07:55 PM
  2. [SOLVED] if statement incorrectly comparing strings
    By Pantheon8 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 14th, 2011, 08:59 PM
  3. Replies: 1
    Last Post: July 22nd, 2011, 07:08 AM
  4. Comparing Strings?
    By wandertheverse in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 10:32 PM
  5. Comparing Strings only using the .length() method - possible?
    By Ryker in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 16th, 2010, 05:52 PM