ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Format date to MM/DD/YYYY

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

  • Format date to MM/DD/YYYY

    I'm doing a select mydate from whereever and dates are displayed as YYYY-MM-DD

    I want to display them as MM/DD/YYYY

    So I used
    Code:
    Select TO_CHAR(mydate,'MM/DD/YYYY')
    but get an error that TO_CHAR in *LIBL type *N not found.

    I found this http://www.ibm.com/developerworks/db.../0211yip3.html

    Tried VARCHAR_FORMAT as well. Tried select Date(mydate) as well...

    any ideas?

  • #2
    Re: Format date to MM/DD/YYYY

    The article you were referencing is for DB2 windows/Linux.
    Try this instead.

    PHP Code:

    Select 
             Char
    Date('1978-01-27'USA ) ) 
    From 
             Sysibm
    .Sysdummy1 
    Predictions are usually difficult, especially about the future. ~Yogi Berra

    Vertical Software Systems
    VSS.biz

    Comment


    • #3
      Re: Format date to MM/DD/YYYY

      okay thats way better than mine......... Yewd the man
      PHP Code:
      A          R DATESR                                             
      A            ISO             L         TEXT
      ('ISO DATE')         
      A            CYMD           7  0       TEXT('CYMD DATE')        
      A            YMD            6  0       TEXT('YMD DATE'

      PHP Code:
            *
            
      //
            // Variable Definition
            //
           
      d stringout       s             30
            
      *

            /
      Free
             exec sql  set option commit
      =*none,datfmt=*iso;

              
      //--------------------------------------------------------
              // MAIN PROGRAM
              //--------------------------------------------------------

              
      exec sql SELECT DAYNAME(Iso)   || ', ' ||
                              
      MONTHNAME(Iso) || ' ' ||
                       
      DAY(Iso) || ', ' || YEAR(Iso)   INTO
                       
      :Stringout from dates;



                 if 
      StringOut <> *blanks;
                   
      dsply Stringout;
                 else;
                   
      Stringout 'Invalid Date Entered';
                   
      dsply Stringout;
                 endif;

              
      exec sql SELECT MONTH(Iso)   || '/' ||
                              
      DAY(Iso)     || '/' ||
                              
      YEAR(Iso)   INTO
                       
      :Stringout from dates;



                 if 
      StringOut <> *blanks;
                   
      dsply Stringout;
                 else;
                   
      Stringout 'Invalid Date Entered';
                   
      dsply Stringout;
                 endif;

                    *
      inlr = *on;

            /
      End-Free 
      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


      • #4
        Re: Format date to MM/DD/YYYY

        I just ran

        Code:
        Select 
                 Char( Date('1978-01-27', USA ) ) 
        From 
                 Sysibm.Sysdummy1
        and I get the msg: column USA not specified in tables.

        Tried
        Code:
        Select 
                 Char( Date('1978-01-27', 'MM/DD/YYYY' ) ) 
        From 
                 Sysibm.Sysdummy1
        and
        Code:
        Char( Date('1978-01-27', MM/DD/YYYY') )
        but didnt work..what am I missing?

        Comment


        • #5
          Re: Format date to MM/DD/YYYY

          Thats because I typed it wrong.

          PHP Code:
          Select
          Char
          Date'1978-01-27') ,USA )
          From
          Sysibm
          .Sysdummy1 
          Predictions are usually difficult, especially about the future. ~Yogi Berra

          Vertical Software Systems
          VSS.biz

          Comment


          • #6
            Re: Format date to MM/DD/YYYY

            thanks, that worked. Was googling when u posted.

            thanks again

            Comment


            • #7
              Re: Format date to MM/DD/YYYY

              @#%@#%@#%@#% Business analysts !!!!!
              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: Format date to MM/DD/YYYY

                Thats Senior Business Analyst.

                Hey, I am getting rusty. I am too busy creating power points and word docs.

                Biznitz Analitz.
                Last edited by kpmac; June 1, 2007, 08:32 AM.
                Predictions are usually difficult, especially about the future. ~Yogi Berra

                Vertical Software Systems
                VSS.biz

                Comment


                • #9
                  Re: Format date to MM/DD/YYYY

                  been off to my SQL Server and .Net world but now back to AS400 stuff

                  Comment


                  • #10
                    Re: Format date to MM/DD/YYYY

                    Post some pretty documents so we can all EWWW and AHHHHH!

                    Nice to have you posting....Have a great weekend!
                    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


                    • #11
                      Re: Format date to MM/DD/YYYY

                      anyway to have it as "dd/mm/yyyy" as well?

                      Looked at this as400 book i have (just remembered i have a book ) and options are ISO, USA,EUR, JIS and LOCAL

                      noway to have it as dd/mm/yyyy?

                      Comment


                      • #12
                        Re: Format date to MM/DD/YYYY

                        try using *EUR

                        if you dont like the "." then

                        PHP Code:
                                                                     
                           exec sql SELECT DAY
                        (Iso)   || '/' ||      
                                           
                        MONTH(Iso)     || '/' ||  
                                           
                        YEAR(Iso)   INTO          
                                    
                        :Stringout from dates
                        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


                        • #13
                          Re: Format date to MM/DD/YYYY

                          silly me, the EUR is dd.mm.yyyy. Didnt notice it.

                          Thanks again for your help.

                          Comment


                          • #14
                            Re: Format date to MM/DD/YYYY

                            Now you are cherry picking.
                            Ha, I didnt notice that either. EUR, who would have thought.
                            PHP Code:

                            Select

                                  Right
                            ChartDate ), ConCat '/' ConCat
                                  SubStr
                            ChartDate ) , 6ConCat '/' ConCat
                                  Left
                            ChartDate ) ,)

                            From(
                            Select
                                   Date
                            ('1978-01-27')as tDate
                            From
                                   Sysibm
                            .Sysdummy1

                            Last edited by kpmac; June 1, 2007, 08:52 AM.
                            Predictions are usually difficult, especially about the future. ~Yogi Berra

                            Vertical Software Systems
                            VSS.biz

                            Comment


                            • #15
                              Re: Format date to MM/DD/YYYY

                              Did I say everyone involved in this thread ROCKS!
                              wait till Birgitta gets here and spanks us all and tells us the right way to do it

                              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