Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003

    Unanswered: Compare two date strings (JAVA)

    Hi there!

    Last edited by jcme; 04-03-03 at 10:28.

  2. #2
    Join Date
    Apr 2003
    What exactly are you trying to pull off here?

    Simplest comparison is to use the equals() method on the String, but this will only tell you if the Strings contain the same data (iow, if it's the same date or not).

    If you want more info, use a SimpleDateFormat object and some java.util.Date objects. Using those you can tell which date is earlier etc.

    The code is quite straightforward:

    String myFormatString = "dd-MM-yyyy"; // for example
    SimpleDateFormat df = new SimpleDateFormat(myFormatString);
    Date date1 = df.parse(string1);
    Date date2 = df.parse(string2);
    if (date1.before(date2)) System.out.println("first date is earliest");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts