6 Replies Latest reply: Oct 1, 2006 3:11 PM by 807598 RSS

    Date problem

    807598
      hello poeple,

      I have a small problem :
      I am getting a date from a JTextField as a string at first. Then
      java.text.SimpledateFormat sdf = new java.text.SimpleDateFormat("dd-MM");
      java.sql.Date d = new java.sql.Date(sdf.parse(strDate).getDate());


      when I enter the following string 09-30, i get an answer like 1970-01-01
        • 1. Re: Date problem
          807598
          Why are you still creating new dates?

          And a day and a month is not a date. There is not enough information present. You need a year.

          If you don't want to have years than don't use dates.
          • 2. Re: Date problem
            807598
            even if I gave the year information, it still does not work. maybe there is some other way to get it right. plz help
            • 3. Re: Date problem
              3004
              even if I gave the year information, it still does
              not work.
              Meaning what? Please post your current code and what problem you're having.

              When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.

              plz help
              Please take the time to write out words such as "please."
              • 4. Re: Date problem
                807598


                java.text.SimpleFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");

                java.sql.Date dt = new java.sql.Date(sdf.parse(strDate).getTime());

                as cotton advised I user the "yyyy" too, and it worked,i.e I can use the dates properly fron the Jtextfield. But, now when I am comparing the 'dt' with dates stored in my MSAccess, it returns null.
                My dates in the table are stored like MM/dd/yyyy.
                Please help

                Thanks
                Kris
                • 5. Re: Date problem
                  807598
                  But, now when I am comparing the 'dt' with dates stored in my MSAccess, it returns null.
                  How do you do your comparison?
                  Please post some relevant code between [code] [/code] tags.
                  • 6. Re: Date problem
                    807598
                    PreparedStatement st1 = conCRT.prepareStatement("
                    SELECT * FROM trace WHERE DateEnt = ?, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                    
                    st1.setDate(1,dt);
                    
                    ResultSet rs1 = st1.executeQuery();
                    this is the satement I use to find the dates in my table
                    Please advise