Results 1 to 4 of 4

Thread: Date

  1. #1
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Cool Date

    Hello to everybody. In the following code i try to compare the date of the check that the user sets and the date of the moment, if the date that the user give is elder than this moment date the date ll insert in the database else the user must give again the date.

    Java Code:
       public void rantevou()throws IOException{
        
             Calendar calendar = Calendar.getInstance();
            
            System.out.println("Give the date of the check");
            
             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String str, str1,str2,str3,str4,str5;
            
                System.out.println("Give the date of the check:");
                    
                    System.out.println("Give the year of the check:");
                    str3=br.readLine();
                    year=Integer.parseInt(str3);
                    System.out.println();
                
               
                    System.out.println("Give the month of the check:");
                    str=br.readLine();
                    month=Integer.parseInt(str);
                    System.out.println();
                    
                    
                    System.out.println("Give the day of the check:");
                    str=br.readLine();
                    day=Integer.parseInt(str);
                    System.out.println();
                    
                    
                    System.out.println("Give the hour of check from-to ***2 hours width****");
                    str4=br.readLine();
                    hour1=Integer.parseInt(str4);
                    System.out.println();
                    str5=br.readLine();
                    hour2=Integer.parseInt(str5);
                    System.out.println();
                    
                    if(
                        (year>=calendar.get(Calendar.YEAR)) && (month>=calendar.get(Calendar.MONTH)) 
                          && (day>=calendar.get(Calendar.DATE)) &&(hour1>=calendar.get(Calendar.HOUR))&&(hour1<hour2) )
                    
                    {
                    System.out.println("The date of the check is :"+day+"/"+month+"/"+year);
                    System.out.println("The hour of the check is: "+hour1+"mexri tis: "+hour2);
                    }
                    
                    else System.out.println("Give again the date of the check:");
        }
    My problem with this method is that when i put date like 18/2/2010 (today is 20/2/2009) the message from the compiler said "give the date again"!! How can I solve this problem???

    Thank you...

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    i'm pretty sure there's a much easier way (probably several actually) to compare dates than where you're starting off: Compare 2 dates - Real's Java How-to

  3. #3
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    ok i ll try it.
    Thank you

  4. #4
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    ok i find a state. When i put the date 2-12-2010 it said to me
    that 2011-01-02 is after 2009-02-22. Ok how can i solve this? i made an array of months with the first element null but i can t put the array in the c1.set(year, month, day);
    ( Calendar c1=Calendar.getInstance();) like c1.set(year,a[month],day);
    Any help?:cool:

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 02:59 PM
  2. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  3. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  4. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  5. Calendar.DATE
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-04-2008, 07:51 PM

Posting Permissions

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