ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

yet another date issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • yet another date issue

    Hi All:

    Here's my code:

    Code:
           test(de) *usa  dob;                               
          if not%error;                                      
             pmdob =      %uns(%char(%Date(dob:*usa):*mdy0));
          endif;
    dob (date of birth) is an input field which i want to convert to pmdob. All works well with this code until this guy with a dob of 7/22/1936. I then get this error:

    HTML Code:
    Message ID . . . . . . :   RNQ0114                                            
    Date sent  . . . . . . :   01/10/07      Time sent  . . . . . . :   13:03:02  
                                                                                  
    Message . . . . :   The year portion of a Date or Timestamp value is not in   
      the correct range (C G D F).                                                
                                                                                  
    Cause . . . . . :   RPG procedure GMCGENCEN in program FARMLIB/GMCGENCEN at   
      statement 006500 requested a conversion to a Date value, from a Timestamp or
      a Date value, and the year of the source is not in the allowable range of   
      the target.                                                                 
      -- The range for a 2-digit year is 1940-2039.                               
      -- The range for a 3-digit year is 1900-2899.                               
      -- The range for a 4-digit year is 0001-9999.                               
    Recovery  . . . :   Check the job log for more information on the cause of the
      error and contact the person responsible for program maintenance.           
    Possible choices for replying to message . . . . . . . . . . . . . . . :      
                                                                           More...
    Does anyone have a work around?

    Thanks
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

  • #2
    Re: yet another date issue

    test(de) *usa dob;
    If Not %Error(); /* -------note the brackets
    pmdob = %uns(%char(%Date(dob:*usa):*mdy0));
    Endif;


    Just guessing here
    Bill
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: yet another date issue

      Hi Bill:

      Brackets didn't help

      Thanks for the effort

      GLS
      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

      Comment


      • #4
        Re: yet another date issue

        At this moment, i have the same error with any date where the year is smaller at 1940 or bigger than 2039. Evaluate the year before the the assignment, and depending if it is inside this range you make it this way, otherwise you should make it in the extensive way.

        Comment


        • #5
          Re: yet another date issue

          Ok then how about this, forget the test op:

          PHP Code:

          Monitor
          ;
          pmdob = %uns(%char(%Date(dob:*usa):*mdy0));
          On-Error;
           
          dsplay "Bad date";
          Endmon
          Bill
          Bill
          "A good friend will bail you out of jail,
          A true friend would be sitting beside you saying,
          'Wow, that was fun.'"

          Comment


          • #6
            Re: yet another date issue

            I just ran this:

            PHP Code:
            D Pmdob           S              6  0 Inz                            
            D dob             S             10    Inz
            ('09/30/2006')              
             /
            Free                                                               
                       test
            (de) *usa  dob;                                       
                      if 
            not %error;                                             
                         
            pmdob =      %uns(%char(%Date(dob:*usa):*mdy0));        
                      Endif;                                                     
                *
            Inlr = *On;                                                     
                Return;                                                          
             /
            End-Free 
            Pmdob = 093006

            when done. No errors. V5R3

            Bill
            Bill
            "A good friend will bail you out of jail,
            A true friend would be sitting beside you saying,
            'Wow, that was fun.'"

            Comment


            • #7
              Re: yet another date issue

              Hi Bill & Cciprian:

              Cciprian is correct dates prior to 1939 or greater than 2040 which generates the error. Bill: The code you provided is within those date ranges try one before 1939.

              This is what i came up with......it's not pretty but i gotta get this done soon and it's functional.

              Code:
              d                 ds                                  
              d year4                          4s 0                 
              d year                           2s 0 overlay(year4:2)
              d month           s              2s 0                 
              d day             s              2s 0                 
              d pmdobusa        s               d   datfmt(*usa) 
                      test(de) *usa doh;                                  
                     if not%error();                                      
                        pmdoh =      %uns(%char(%Date(doh:*usa):*mdy0));  
                     endif;                                               
               
                          //   dont format birth date if missing          
                      test(de) *usa  dob;                                 
                     if not%error();                                      
                           Monitor;                                       
                           pmdob = %uns(%char(%Date(dob:*usa):*mdy0));    
                               On-Error;                                      
                               pmdobusa= %date(dob:*usa);                     
                                        Year4    = %Subdt(pmdobusa:*Y); 
                                        Month    = %Subdt(pmdobusa:*M); 
                                        Day      = %Subdt(pmdobusa:*D); 
                              pmdob=(Month*10000) + Day * 100 + Year;                         
                          Endmon;                                   
                    endif;
              Thanks to both of you for the assist
              GLS
              The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

              Comment


              • #8
                Re: yet another date issue

                This error only presented if you working with dates where the format of the year is 4 positions, and it is outside of this range. If you work with date with only 2 position for the year and move later with movel the century will work fine.

                Comment


                • #9
                  Re: yet another date issue

                  Your problem is you are trying to get a six digit date (2 col year). Dates in this format are ONLY supported from 1940 - 2039. So 111539 is in 2039 and 111540 is in 1940.

                  As you are discovering, you need to use a 4 col year format like *USA or *ISO.

                  What is the format for the date coming in ? 8 cols. I am guessing. What format are you trying to end up with ? You generally cannot store birthdates in a 6 col field, you will constantly be hitting dates outside the range.

                  And if the date errors out, you are putting the "bad" date in the database anyway ? Then why are you testing the date in the first place ?

                  Comment


                  • #10
                    Re: yet another date issue

                    Here's a sample that might do what you want:
                    PHP Code:
                              D dob                            8S 0
                         D dobA                           8A
                         D pmdob                          6S 0
                         D
                          
                    //    test if this is a valid date in USA format
                          
                    /FREE
                           Monitor
                    ;
                             
                    pmdate = %date(dob:*USA);
                           
                    On-Error;
                             
                    //     (throw error message .... or whatever)
                           
                    EndMon;
                     
                           
                    //   convert the date to a 6 digit field
                           
                    dobA  = %editC(dob:'X');
                           
                    pmdob = %dec(%subst(dobA:1:4)
                               + %
                    subst(dobA:7:2):6:0);
                          /
                    END-FREE 

                    Comment


                    • #11
                      Re: yet another date issue

                      Hi Arrow:

                      The input field is 10 alpha in usa format. I'm going to mmddyy numeric format (not my design). The Initial test(DE) validates that I have a valid USA date before I convert it. If it is not a valid date the output field mmddyy numeric should be zeros.

                      Your code is way more elegant than mine but that was a 1 time program that had to be done yesterday. I'm sure I will be using it in the near future.

                      Thanks for the input

                      GLS
                      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                      Comment


                      • #12
                        Re: yet another date issue

                        Well SOB I tried 1939 and it does blow away.
                        But I see the solution above works well.

                        Good Luck
                        Bill
                        Bill
                        "A good friend will bail you out of jail,
                        A true friend would be sitting beside you saying,
                        'Wow, that was fun.'"

                        Comment

                        Working...
                        X