ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Manipulating Dates

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

  • Manipulating Dates

    Hello Everyone.

    I am new (1.5 weeks) to RPG. I have picked up quite a few things and with some help have written to the screen and the database.

    I've browsed around the internet for a solution to my question but haven't been able to find something solid, so I will ask it here.

    If I have a date defined as a *USA format, what is the best way to display dd/mm/yy on the screen and still store the date in the database as the *USA format.



    Thanks for any help.

    -Adein

  • #2
    Re: Manipulating Dates

    on your H spec use DATFMT(*EUR)
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: Manipulating Dates

      *DMY for DD/MM/YY
      *EUR for DD.MM.YYYY
      Patrick

      Comment


      • #4
        Re: Manipulating Dates

        Thank you for your fast reply.

        Again I am new so forgive me.

        In my Source Code file I can specifiy an H record for the date format.

        Currently in my Phyisical file I have the date defined as *USA.

        Other than the H spec on in the program I won't need to do anything else?

        Thanks again,

        -A

        Comment


        • #5
          Re: Manipulating Dates

          If it's for diplaying, you can use DATFMT(*DMY) in SDA for the field.
          Also, you can declare a field in D specification with the keyword DATFMT

          look this link : http://www.itjungle.com/fhg/fhg051904-story01.html
          Patrick

          Comment


          • #6
            Re: Manipulating Dates

            Just for information. A real date is always stored as 4 byte binary value repesenting the number of days since x. A date format whereever it is used makes only this 4 Byte binary value readeable. A date format specified in the DDS is only used to make the date readeable with WRKF.

            I'd not change the Date Format specifed in the H-Spec to anything else than *ISO. Instead I'd specify the date format on field level and only for fields that are displayed or printed.

            Birgitta

            Comment


            • #7
              Re: Manipulating Dates

              Try this..

              for display file

              *date keyword use edtcode Y it will giv you dd/mm/yy format

              and for Database file concern u will not define anything ih Header Spec default it will *ISO Format..

              Since you date in P.F. are *EUR define
              Code:
              h datfmt(*eur)
              Pramendra Pandeya
              Young people knows how to run fast but old people knows the way..

              Comment


              • #8
                Re: Manipulating Dates

                most of the cases....they wont use date format as USA,EUR like that, simply they use numeric value for date values.because if u declared date field in database it becomes overhead when ur picking the records eg..between the two dates. in order to display date like 12/12/2010 like dat.u move the numeric value to data structure and use some separators between the numeric value as you want.simply move the data structure to that display file field

                Comment


                • #9
                  Re: Manipulating Dates

                  Originally posted by rajapandian View Post
                  most of the cases....they wont use date format as USA,EUR like that, simply they use numeric value for date values.because if u declared date field in database it becomes overhead when ur picking the records eg..between the two dates. in order to display date like 12/12/2010 like dat.u move the numeric value to data structure and use some separators between the numeric value as you want.simply move the data structure to that display file field
                  you're suggesting that he revert back to the 1980-1990s methods? really?
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment


                  • #10
                    Re: Manipulating Dates

                    Noooooooooooooooooooooooooooooooo please...too old scul

                    Comment


                    • #11
                      Re: Manipulating Dates

                      If you have the date defined in the database as *USA, you don't want to change that. the simplest was to get what you want IMHo is to define a work field to display in the format you want.

                      For example if DBDate is your database date, just output DateDMY to the screen.

                      Code:
                           D DateDMY         S               D   Datfmt(*DMY/)
                            *
                           C                   Eval      DateDMY = DBDate
                      Then it doesn't matter if the format in the DB changes, nor if some other dates in the pgm are different formats, or somebody else changes the H spec.

                      in any case, you may get an error here is your dates are pre-1940 or after 2039, due to limitations of the DMY format.

                      Comment


                      • #12
                        Re: Manipulating Dates

                        Or you can do it this way:
                        Code:
                             A            TODT            L  B  9 56TEXT('To Date')                  
                             A                                      MAPVAL(('1940-01-01' *BLANK))    
                             A                                      DATFMT(*JOB)      
                             A                                      DATSEP(*JOB)
                        You can use the job's attribute to control the date format. The job date format must be one of *YMD, *MDY, *DMY or *JUL.

                        Or you can hard code the screen to a specific format. DATFMT(*DMY)

                        The MAPVAL keyword causes '1940-01-01' to be displayed as blanks on output and return operator entered blanks as '1940-01-01'.

                        This way the program runs in *ISO and the screen does all the conversions.
                        Last edited by Denny; November 19, 2009, 12:57 PM.
                        Denny

                        If authority was mass, stupidity would be gravity.

                        Comment


                        • #13
                          Re: Manipulating Dates

                          Thank you to everyone!


                          Then it doesn't matter if the format in the DB changes, nor if some other dates in the pgm are different formats, or somebody else changes the H spec.

                          in any case, you may get an error here is your dates are pre-1940 or after 2039, due to limitations of the DMY format.
                          What is /why the limitation?

                          Assuming the the product will be used past 2040, what would be a work around? I mean I don't know if PRG will be around in 2040, but it's lasted thus far. Right?!?

                          I understand that the Data Structure is old school, but would it not incur the above limitation?

                          And just to think this all stems from the end user not wanting to type a '20' for the century.
                          Last edited by Adein; November 19, 2009, 01:12 PM.

                          Comment


                          • #14
                            Re: Manipulating Dates

                            The limitation is only on the 2-digit date formats. If you enter a date like 11/19/50 is the system to understand this as 1950 or 2050? IBM decided the "40" as the cutoff, assuming this covers the hundred years most likely to be used. You solve this whole issue by using a 4-digit date format.
                            If you convert the date to an char or dec field, you can put any date you want, but what does that get you. You still wouldn't know 11/19/50 is which century.
                            Presumably, as we approach 2039, either IBM will adjust the default for the 2-digit dates, or programmers will change to 4-digit dates. If you want to make sure you don't have to change the program for 30 years, do not depend on the 2-digit formats.
                            My only complaint is "date" fields cannot be "blank" or "zero". So a "ship date" for a product that hasn't shipped yet has to have a "dummy" date (like *LOVAL), and I have to program around it.
                            BTW, Microsoft does the same kind of thing with Excel dates.

                            Comment


                            • #15
                              Re: Manipulating Dates

                              I wanted to thank everyone for their help. I have been able to have the user input a two digit year and store the full year in the database.

                              I used arrow's approach with the database def showing a true date with datfmt(*USA), the screen def as true date with datfmt(*mdy), and using eval to move from one format to another.


                              How I have a secondary question, still related to working with dates, so I will keep in in this post.

                              How can I when displaying the field, not show the default date?

                              I read on http://search400.techtarget.com/tip/...28844,00.html# that you can test for the default date, if found display a blank field.

                              I defined a work variable as a date with the default value (01/01/1940), then I can compare the screen value to the work value. Once they evaluate to be the same, how do I clear out the date that is going to be displayed?

                              Again thanks for the help. I am learning a lot from all the conversation.
                              Last edited by Adein; November 20, 2009, 01:18 PM.

                              Comment

                              Working...
                              X