ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Comparing Dates

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

  • Comparing Dates

    Hey guys I need to comapare two dates feilds but the roblem is that one of the eild is packed decimal and the other is zoned decimal .How do I compare these values.(Is there any way to convert the values to dates and then compare them I am trying to comapare it in a cl program).

  • #2
    Re: Comparing Dates

    Just move them both to a date defined field of your choice..

    make sure to test prior
    Code:
                   test(de) *cymd lhvndt;                                                              
                    if not%error;                                                                       
                     isodate = %date(lhvndt:*cymd);                                                     
                     s5vndt = %dec(isodate:*mdy);                                                       
                    else;                                                                               
                     clear s5vndt;                                                                      
                    endif;
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Comparing Dates

      Thanks jamie tht worked for me Now I want to separate each part from date to check for its validity how can I do that.Do ineed to create a ds and separate each part or anything els.

      Comment


      • #4
        Re: Comparing Dates

        if the test(de) is successful you shouldn't have to check anything else. if successful it's a valid date, if not then it is not a valid date.
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: Comparing Dates

          but as a learning experience look at bif %subdt its pretty nerdy!

          http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0925083595.htm

          j
          amie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: Comparing Dates

            Wouldn't it be better to provide a link to the current (Release 7.1) RPG Reference (even though %SUBDT didn't change since Release 5.1):

            http://publib.boulder.ibm.com/infoce...c092508881.htm

            Birgitta

            Comment


            • #7
              Re: Comparing Dates

              sure .. I was just lazy Thank you
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: Comparing Dates

                gracias everybody

                Comment


                • #9
                  Re: Comparing Dates

                  Hey guys I am getting this error

                  Receiver value too small to hold the result

                  my code:

                  Code:
                   /free
                   date0    s      D   datfmt(*mdy);
                  
                  date0= %date(dateofjoining:*mdy);--> this line
                  /end free
                  
                  dateof joining is a numeric database field of length 8 p 0

                  Comment


                  • #10
                    Re: Comparing Dates

                    In which format is the date stored?
                    YYYYMMDD (*ISO) or YYMMDD (*YMD) or MMDDYYYY (*USA) or MMDDYY (*MDY) or DDMMYYYY (*EUR) or DDMMYY (*DMY).

                    If it is stored in format *ISO, *USA, *EUR and you want to convert the numeric date into format *MDY, you need to make sure the date will be in the range between 01/01/1940 and 12/31/2039.

                    If it is stored in format *YMD, *DMY or *MDY, try to format DateOfJoining into 6P 0
                    Code:
                    /Free
                       Date0 = %Date(%Dec(DateOfJoining: 6: 0): *MDY);
                    /End-Free
                    You may also use Opcode TEST(DE) to check for a valid date.

                    Birgitta

                    Comment


                    • #11
                      Re: Comparing Dates

                      also if the date in the numeric field is like MMDDYYYY then it is *USA format not *MDY.
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: Comparing Dates

                        ok this is the problem i need to find if a date(numeric of length 8) is in betweeen two particular dates.

                        so i stored it in a date varaiable by
                        Code:
                        date0= %date(dateofjoining:*usa);-->
                        now when i comapre it with the other two dates its incompatible (it doesn't give an error though)since the other two dates are in *mdy and this one is in *usa.


                        So basically is there a way that i could anyhow get the 8 digit numeric into 6 digit date so that i can compare it with other two dates or viceversa.

                        Thanks all u guys for helping me(noob) please bear with me ..

                        Comment


                        • #13
                          Re: Comparing Dates

                          if they are true date field the format doesn't matter as far as the comparison goes. dates aren't really formatted in storage the format option on affects the "human-readable" display of the dates.
                          I'm not anti-social, I just don't like people -Tommy Holden

                          Comment


                          • #14
                            Re: Comparing Dates

                            Remember that the 2nd parm supplied to the %date() is the format of the NON-DATE field, and doesn't have to agree with the format of the date field. If you are getting incompatable fields, you are not comparing date fields - you are comparing the numeric on one of them.

                            Comment


                            • #15
                              Re: Comparing Dates

                              post the actual data you are trying to compare....and we can post code to do it.

                              thanks
                              Jamie
                              All my answers were extracted from the "Big Dummy's Guide to the As400"
                              and I take no responsibility for any of them.

                              www.code400.com

                              Comment

                              Working...
                              X