Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default regarding error of comparison of dates

    'else' without 'if'
    else if(cal.after(currentcal))

    the above is the error message while compiling the below programme
    import java.util.*;
    import java.text.*;

    public class CompareDate
    {
    public static void main(String args[])
    {
    Calendar cal = Calendar.getInstance();
    Calendar currentcal = Calendar.getInstance();
    cal.set(2000, Calendar.JUNE, 29);
    currentcal.set(currentcal.get(Calendar.YEAR),curre ntcal.get(Calendar.MONTH), currentcal.get(Calendar.DAY_OF_MONTH));

    if(cal.before(currentcal)){

    System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+")is greater than the given date " + newSimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));



    else if(cal.after(currentcal))
    System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+") is less than the given date "+ newSimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));



    else
    System.out.println("Both date are equal.");

    }

    }
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,998
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by gkpallavii2010 View Post
    if(cal.before(currentcal)){

    System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+")is greater than the given date " + newSimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));



    else if(cal.after(currentcal))
    You forgot a right curly bracket:

    Java Code:
        if(cal.before(currentcal)){
    
          System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+")is greater than the given date " + newSimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));
    
    
    } // <--- this one
        else if(cal.after(currentcal))
    kind regards,

    Jos

Similar Threads

  1. String Comparison
    By evant8950 in forum Java Applets
    Replies: 6
    Last Post: 04-22-2009, 08:11 AM
  2. Comparison of Strings
    By Cero.Uno in forum New To Java
    Replies: 3
    Last Post: 02-11-2008, 02:46 AM
  3. Date comparison
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 06:34 PM
  4. Parsing Dates for Comparison
    By Rageagainst20 in forum New To Java
    Replies: 1
    Last Post: 12-19-2007, 05:50 AM
  5. String comparison
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 12-18-2007, 12:16 AM

Posting Permissions

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