1 2 Previous Next 15 Replies Latest reply: Apr 1, 2014 10:49 AM by rp0428 RSS

    compare date

    Tshifhiwa

      hi am trying to do this

      hi am trying to do this

       

      The value date of transaction must be within the active Date >= and Inactive Date <= date range item

       

       


       

       

       

        • 1. Re: compare date
          gimbal2

          This is going from bad to worse, now you're just posting an unreadable mess and not even asking a question?

          • 2. Re: compare date
            Tshifhiwa

            sorry i did not format the code i did change now

             

            i what to do the following

            The value date of transaction must be within the active Date >= and Inactive Date <= date range item

            date of transaction=sDate

            active Date=s_ActiveDate

            Inactive Date=s_InactiveDate

             

            if(!isActive(sDate,s_InactiveDate, s_ActiveDate)){

             

            System.out.println("comingdate "+sActive);

             

            }

             

             

            public boolean isActive( String sValueDate, String sInactive, String sActive) throws SQLException

                {

                    Date i_date;

                    Date a_date;

              

                    System.out.println("PasseddateTrans "+sValueDate);

                    try

                    {

                        System.out.println("comingdate "+sActive);

                        System.out.println("comingdateTrans "+sValueDate);

                        System.out.println("comingdatesInactive "+sInactive);

                        if(!isBlank(sActive)){

                        if(!isBlank(sValueDate)){

                        a_date = new SimpleDateFormat("yyyy-MM-dd").parse(sActive);

                        Date dt_valueDate = new SimpleDateFormat("yyyy-MM-dd").parse(sValueDate);

                  

                        System.out.println("comingdateAfter "+a_date);

                        System.out.println("comingdateDateTransAfter "+dt_valueDate);

                  

                        if(!isBlank(sInactive))

                        {

                            i_date = new SimpleDateFormat("yyyy-MM-dd").parse(sInactive);

                            if (dt_valueDate.compareTo(i_date) <= 0 && dt_valueDate.compareTo(a_date) >= 0)

                                System.out.println("Comapredate dt_valueDate "+ dt_valueDate );

                                System.out.println("Comapredatei_date "+ i_date );

                                System.out.println("*******************&&&&"  );

                                System.out.println("dt_valueDate****** "+dt_valueDate);

                                 System.out.println("a_date******"+a_date);

                             

                            {

                                return true;

                            }

                        }else

                        {

                            if (dt_valueDate.compareTo(a_date) >= 0)

                            {

                                return true;

                            }

                        }

                        }

                        }

                    } catch (ParseException ex)

                    {

                        java.util.logging.Logger.getLogger(Validate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

                    }catch(NullPointerException npe)

                    {

                        return false;

                    }

              

                    return false;

                }

             

            public boolean isBlank(String s_val)
                {
                    boolean flag = false;
                    try
                    {
                        if (s_val.trim().equals("") || s_val == null)
                        {
                            flag = true;
                        }
                    } catch (NullPointerException npe)
                    {
                        flag = true;
                    }
                    return flag;
                }

             

             

            the value am getting

             

            PasseddateTrans 2014-02-26

            comingdate 2013-06-01 00:00:00

            comingdateTrans 2014-02-26

            comingdatesInactive 2014-03-24 10:59:23

            comingdateAfter Sat Jun 01 00:00:00 CAT 2013

            comingdateDateTransAfter Wed Feb 26 00:00:00 CAT 2014

            Comapredate dt_valueDate Wed Feb 26 00:00:00 CAT 2014

            Comapredatei_date Mon Mar 24 00:00:00 CAT 2014

            *******************&&&&

            dt_valueDate****** Wed Feb 26 00:00:00 CAT 2014

            a_date******Sat Jun 01 00:00:00 CAT 2013

            selectedColumn CRD_POS_DATE_ACTIVE

            Column1**** VISA

            Query**** SELECT CRD_POS_DATE_ACTIVE FROM  crd_pos_entry_mode pos,card_indicator ind where pos.crd_pos_crd_ind_code = ind.crd_ind_code and pos.crd_pos_entry_mode_code1 = ? and ind.crd_ind_name = 'VISA'

            FinalQueryCategory**** 2014-03-20 00:00:00

            selectedColumn CRD_POS_DATE_INACTIVE

            Column1**** VISA

            Query**** SELECT CRD_POS_DATE_INACTIVE FROM  crd_pos_entry_mode pos,card_indicator ind where pos.crd_pos_crd_ind_code = ind.crd_ind_code and pos.crd_pos_entry_mode_code1 = ? and ind.crd_ind_name = 'VISA'

            FinalQueryCategory**** 2014-03-31 07:47:15

            *****printelectcardindicator122****** VISA

            printelectcardindicators_posEntryMode++++++ 01

            *****++++printelectcardindicators_ActiveDate****** 2014-03-20 00:00:00

            ++++++printelectcardindicator++++++s_InactiveDate 2014-03-31 07:47:15

            PasseddateTrans 2014-02-26

            comingdate 2014-03-20 00:00:00

            comingdateTrans 2014-02-26

            comingdatesInactive 2014-03-31 07:47:15

            comingdateAfter Thu Mar 20 00:00:00 CAT 2014

            comingdateDateTransAfter Wed Feb 26 00:00:00 CAT 2014

            Comapredatei_date Mon Mar 31 00:00:00 CAT 2014

            *******************&&&&

            dt_valueDate****** Wed Feb 26 00:00:00 CAT 2014

            a_date******Thu Mar 20 00:00:00 CAT 2014

            112233printfinaltransctiondate33 2014-02-26

            formatedtransactiondate 2014-02-26

            112233printfinaltransctiondate33 2014-02-26

            transctiondate 111112014-02-26

            selectedColumn AD_RPT_QUAL_ACTIVE_DATE

            Column1**** BOPCARD RESIDENT

            Query**** SELECT AD_RPT_QUAL_ACTIVE_DATE FROM  ad_rpt_qual_link rpt, reporting_qualifier qa where qa.report_qual_code = rpt.ad_rpt_qual_rpt_qual_code and rpt.ad_rpt_qual_ad_code = ? and qa.report_qual_name = 'BOPCARD RESIDENT'

            FinalQueryCategory**** 1950-01-01 00:00:00

            selectedColumn AD_RPT_QUAL_INACTIVE_DATE

            Column1**** BOPCARD RESIDENT

            Query**** SELECT AD_RPT_QUAL_INACTIVE_DATE FROM  ad_rpt_qual_link rpt, reporting_qualifier qa where qa.report_qual_code = rpt.ad_rpt_qual_rpt_qual_code and rpt.ad_rpt_qual_ad_code = ? and qa.report_qual_name = 'BOPCARD RESIDENT'

            FinalQueryCategory****

            112233printfinaltransctiondate33 2014-02-26

            12222transctiondate 11111 2014-02-26

            112233printfinaltransctiondate33 2014-02-26

            12222transctiondate 11111 2014-02-26

            112233printfinaltransctiondate33 2014-02-26

            12222transctiondate 11111 2014-02-26

            112233printfinaltransctiondate33 2014-02-26

            12****222transctiondate 111112014-02-26

            112233printfinaltransctiondate33 2014-02-26

            1***2222transctiondate**** 111112014-02-26

            112233printfinaltransctiondate33 2014-02-26

            merchantdatecoming 2014-02-26

            112233printfinaltransctiondate33 2014-02-26

            1***2222t211ransctiondate**** 111112014-02-26

            112233printfinaltransctiondate33 2014-02-26

            1***2222transctiondate345333**** 111112014-02-26

            112233printfinaltransctiondate33 2014-02-26

            • 3. Re: compare date
              rp0428

              So what is the PROBLEM you are trying to solve? You posted a bunch of code but you never said what your problem or issue is.

               

              the value am getting

              Huh? You say the code you posted is actually giving you Queries of a database? Not possible - you must have other code that has those queries in it.

               

              Explain, in English, WHAT you are trying to do. It looks more like you are:

              1. querying a database for a date value - AD_RPT_QUAL_ACTIVE_DATE

              2. looping through the result set

              3. testing that date against string constants for 'active' and 'inactive'

              4. doing 'something' with the result

               

              And why are you writing code like this?

              if(!isBlank(sActive)){ 

                          if(!isBlank(sValueDate)){

              . . . // a whole bunch of code

                          return false;

                      }

                

                      return false;

                  }

               

              Validate the parameters BEFORE you start trying to use them.

               

              Also, even code written with those tests embedded in it you should generally put the SHORT branch of IF statements first.

               

              In your case you simply want to return IMMEDIATELY if a parameter is null or invalid. So test them and return as needed.

              // validate parameter1

              if (isBlank(sActive)) {

                return false;

              }

               

              // validate parameter2

              is (isBlank(sValueDate)) {

                return false;

              }

              . . .

              //; validate the other parameters as needed

              . . .

              code goes here

              That code structure is:

              1. much MUCH more readable - you don't have to scan through a lot of code to see where (or IF) the ELSE branch is.

               

              2. much easier to understand - you can EASILY see the validations that are being performed since each validation is done separately.

               

              3. much easier to maintain - each part of the functionality is separate and distinct from the other parts. That makes it easy to find the part of the code that needs to be looked at or tested. It also makes it easier to add (or modify) parameter validation code WITHOUT accidentally changing the rest of the code.

               

              The goal is to write simple, modular code. Simple modules are easier to write and easier to test. They can then be combined to form more complex modules.

              • 4. Re: compare date
                Tshifhiwa

                am using the

                !isblank to check for null value or blank value

                public boolean isBlank(String s_val)

                    {

                        boolean flag = false;

                        try

                        {

                            if (s_val.trim().equals("") || s_val == null)

                            {

                                flag = true;

                            }

                        } catch (NullPointerException npe)

                        {

                            flag = true;

                        }

                        return flag;

                    }

                 

                this is what i what to do

                check value date of transaction must be within the active Date >= and Inactive Date <= date range item

                • 5. Re: compare date
                  TPD-Opitz

                  if (s_val.trim().equals("") || s_val == null)

                  Expressions are evaluated from left to right. So if s_val refers to the null object you get a NPE by s_val.trim() and the rest of this line is never executed.

                  Exchange left and right oh the || Operator to get rid of the try/catch construct.

                   

                  bye

                  TPD

                  • 6. Re: compare date
                    Tshifhiwa

                    sorry what do you mean Exchange left and right oh the || Operator to get rid of the try/catch construct.

                    • 7. Re: compare date
                      TPD-Opitz

                      what do you mean Exchange left and right oh the || Operator

                      Are you puzzled by my spelling mistake (oh->of)?

                       

                      to get rid of the try/catch construct.

                      try/catch is for handling errors, not for flow control. So using a try/catch just because you are not able or (even worse) not willing to find the root cause of that NPE is not acceptable in production code.

                       

                      bye

                      TPD

                      • 8. Re: compare date
                        Tshifhiwa

                        ok you mean

                         

                        public boolean isBlank(String s_val)

                            {

                                boolean flag = false;

                             

                             

                                        if (s_val == null )

                                    {

                                        flag = true;

                                    }

                             

                                

                                return flag;

                            }

                        • 9. Re: compare date
                          TPD-Opitz

                          Almost,

                           

                          If you had unittest for your code you'd find that you changed the logic of your code.

                           

                           

                          bye

                          TPD

                          • 10. Re: compare date
                            Tshifhiwa

                            public boolean isBlank(String s_val)

                                {

                                    boolean flag = false;

                                 

                                   

                                            if (s_val == null  || s_val.trim().equals("") )

                                        {

                                            flag = true;

                                        }

                                 

                                    }

                                    return flag;

                                }

                            • 11. Re: compare date
                              TPD-Opitz

                              That's it!

                               

                              bye

                              TPD

                              • 12. Re: compare date
                                Tshifhiwa

                                ok will this code

                                public boolean isActive(String sValueDate, String sInactive, String sActive) throws SQLException

                                    {

                                        Date i_date;

                                        Date a_date;

                                      

                                        System.out.println("PasseddateTrans "+sValueDate);

                                        try

                                        {

                                            System.out.println("comingdate "+sActive);

                                            System.out.println("comingdateTrans "+sValueDate);

                                            System.out.println("comingdatesInactive "+sInactive);

                                            if(!isBlank(sActive)){

                                            if(!isBlank(sValueDate)){  

                                            a_date = new SimpleDateFormat("yyyy-MM-dd").parse(sActive);

                                            Date dt_valueDate = new SimpleDateFormat("yyyy-MM-dd").parse(sValueDate);

                                          

                                            System.out.println("comingdateAfter "+a_date);

                                            System.out.println("comingdateDateTransAfter "+dt_valueDate);

                                          

                                            if(!isBlank(sInactive))

                                            {

                                                i_date = new SimpleDateFormat("yyyy-MM-dd").parse(sInactive);

                                                if (dt_valueDate.compareTo(i_date) <= 0 && dt_valueDate.compareTo(a_date) >= 0)

                                                    System.out.println("Comapredate dt_valueDate "+ dt_valueDate );

                                                    System.out.println("Comapredatei_date "+ i_date );

                                                    System.out.println("*******************&&&&"  );

                                                    System.out.println("dt_valueDate****** "+dt_valueDate);

                                                     System.out.println("a_date******"+a_date);

                                                    //System.out.println("Comapredate"+ dt_valueDate "<"+ i_date+ "<"+ dt_valueDate ">"+ a_date);

                                                {

                                                    return true;

                                                }

                                            }else

                                            {

                                                if (dt_valueDate.compareTo(a_date) >= 0)

                                                {

                                                    return true;

                                                }

                                            }

                                            }

                                            }

                                        } catch (ParseException ex)

                                        {

                                            java.util.logging.Logger.getLogger(Validate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

                                        }catch(NullPointerException npe)

                                        {

                                            return false;

                                        }

                                      

                                        return false;

                                    }

                                 

                                do this

                                check value date of transaction must be within the active Date >= and Inactive Date <= date range item

                                • 13. Re: compare date
                                  jwenting

                                  well, what do you think it does?

                                  Have you tested it? What did it do?

                                  If not, why haven't you tested it?

                                  We're not your code checking service, let alone your testing department.

                                   

                                  It's also massively convoluted code just to compare some dates. Start at the basics, get them right, THEN add code to handle things like input and output.

                                  • 14. Re: compare date
                                    Tshifhiwa

                                    it does work when

                                    if(isActive(sDate(),s_InactiveDate, s_ActiveDate)) is this the right way to do it

                                    1 2 Previous Next