1 2 Previous Next 16 Replies Latest reply: Oct 26, 2007 10:50 AM by 807600 RSS

    Date comparision

    807600
      I have a requirement Where i get a Date property from dbase..I need to check if this date is older than 45 days and do some business validations..
      How can i find this ?
        • 1. Re: Date comparision
          807600
          you can use the java.util.GregorianCalender object..

          There are many methods of this class which will be useful for your reqiurement.

          You can use the after() method.
          • 2. Re: Date comparision
            807600
            I am unable to figure out.. the logic....Plz can u put some effort..
            • 3. Re: Date comparision
              796254
              cnu_coder wrote:
              I am unable to figure out.. the logic....Plz can u put some effort..
              Where's your effort?

              http://www.exampledepot.com/egs/java.util/pkg.html#Dates

              %
              • 4. Re: Date comparision
                807600
                It's likely going to be simpler and more efficient to do this directly in the SQL code using DB functions - what DB are you using?
                • 5. Re: Date comparision
                  807600
                  Calendar cal = Calendar.getInstance();
                          
                          cal.add(Calendar.DATE,45);    // the date in 45 days time.
                  //      cal.add(Calendar.DATE,-45);   to get the date 45 days ago from today
                  Then what you can do is use the compareTo method to compare your date from the database to the new date that is 45 days older or newer (depending what you what)

                  I'm sure you can figure the rest out.
                  • 6. Re: Date comparision
                    807600
                    I'm sure you can figure the rest out.
                    Given his reply of "I am unable to figure out.. the logic....Plz can u put some effort..", I'd be willing to place a wager on that.
                    • 7. Re: Date comparision
                      807600
                      jToohey wrote:
                      I'm sure you can figure the rest out.
                      Given his reply of "I am unable to figure out.. the logic....Plz can u put some effort..", I'd be willing to place a wager on that.
                      Ha ha, most probably... I did like the way he asks someone else to put in effort since he is incapable of doing so himself.
                      • 8. Re: Date comparision
                        807600
                        __colin wrote:
                        jToohey wrote:
                        I'm sure you can figure the rest out.
                        Given his reply of "I am unable to figure out.. the logic....Plz can u put some effort..", I'd be willing to place a wager on that.
                        Ha ha, most probably... I did like the way he asks someone else to put in effort since he is incapable of doing so himself.
                        Later he'll wrinkle his nose, point and say, "you missed a spot".
                        • 9. Re: Date comparision
                          807600
                          here is my effort after the first reply..

                          Got a date from dB.= 1990/01/1

                          Step 1:
                          Calendar dateFromDb = new GregorianCalendar(1990, Calendar.JANUARY, 1);

                          Step 2:

                          Calendar currentDate = new GregorianCalendar();

                          Step 3.
                          What i did is.. I have added 45 days to dateFromDb value.
                          like this.
                          Calendar c = Calendar.getInstance();
                          c.setTime(dateFromDb );
                          c.add(Calender.DATE, amount);

                          STEP4;
                          i want them to compare like
                          if this date is not equal to current date then.. i would proceed with my logic.

                          But ,, i having some probelms in step3.. that was my effort.

                          I might be late in posting reply but not that i havent put my effort.

                          But, you guys are so helpful.. Very much appreciated...
                          • 10. Re: Date comparision
                            807600
                            OP, you state: "Where i get a Date property from dbase"

                            I ask again ... why not do this in the DB itself?
                            • 11. Re: Date comparision
                              807600
                              i having some probelms in step3.
                              Explain, please.
                              • 12. Re: Date comparision
                                807600
                                I have just checked about the useablity of checking this on the database level. Actuallly, the reason for not doing this, the property that i get is retrieved for some other functionality as a complete BusinessObject , from which i get this value and do some other rules..
                                so i have to let this go this way..
                                • 13. Re: Date comparision
                                  807600
                                  Got a date from dB.= 1990/01/1

                                  Step 1:
                                  Calendar dateFromDb = new GregorianCalendar(1990, Calendar.JANUARY, 1);

                                  Step 2:

                                  Calendar currentDate = new GregorianCalendar();

                                  Step 3.
                                  What i did is.. I have added 45 days to dateFromDb value.
                                  like this.
                                  Calendar c = Calendar.getInstance();
                                  c.setTime(dateFromDb );
                                  c.add(Calender.DATE, amount);


                                  Actually,, the mistake appears to be ... when i retrieved the date property . i should convert to Calender Object as i did Calendar dateFromDb = new GregorianCalendar(1990, Calendar.JANUARY, 1);

                                  Is this the correct way..

                                  So in the end when i compare the date added with 45 days with current Date..
                                  it is always return 1.. So .. that was the problem..

                                  But i guess i am very close now. i willl be able to find the loop.... Thanks again all..
                                  • 14. Re: Date comparision
                                    807600
                                    Your problem with step 3 is that the setTime takes a Date object, you're passing a Calendar
                                    c.setTime(dateFromDb.getTime());
                                    Edited by: __colin on Oct 26, 2007 9:37 AM
                                    1 2 Previous Next