ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

ISO date to numeric YYYYMMDD

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

  • ISO date to numeric YYYYMMDD

    So I need to take an ISO date and transform it to YYYYMMDD numeric because that is how it is stored in the DB.

    So I thought I was clever and wrote this...

    Code:
    tmpfdate = %dec(%char(%dec(%subdt(fdate:*years):4:0)) +
                               %char(%dec(%subdt(fdate:*months):2:0)) +
                               %char(%dec(%subdt(fdate:*days):2:0)):8:0);
    However, when the ISO date of 2009-02-01 is entered, this produces tmpfdate = 00200921

    if the date is 2009-02-01 then the tmpfdate is 02009228.

    Is there an easier way to do this? Shouldn't this method work?

    Is the %dec inside of the %char screwing it up and not giving me the leading 0?
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

  • #2
    Re: ISO date to numeric YYYYMMDD

    Code:
    isodate       d 
    usadate       8 0
    
    isodate = %date();
    
    usadate  = %dec(isodate:*usa)
    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: ISO date to numeric YYYYMMDD

      Well wasn't that simple? Sheesh. Thanks Jamie.
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment


      • #4
        Re: ISO date to numeric YYYYMMDD

        tmpfdate = %dec(fdate);

        It is that simple !
        Philippe

        Comment


        • #5
          Re: ISO date to numeric YYYYMMDD

          Just for reference sake... YYYYMMDD needs to be %dec(isodate:*ISO);


          ***EDIT***
          /*Wrong statement...*/

          ***DOUBLE EDIT***
          Mercruy, you DO need the *ISO in order to get YYYYMMDD. Otherwise it just makes it MMDDYYYY.
          Last edited by bryce4president; March 17, 2009, 07:24 AM.
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: ISO date to numeric YYYYMMDD

            Originally posted by jamief View Post
            Code:
            isodate       d 
            usadate       8 0
            
            isodate = %date();
            
            usadate  = %dec(isodate:*usa)


            I'll have to chec into this %dec() BIF

            I've been doing it longhand forever!

            usadate = %int( %char(isodate : *usa0) )
            Your friends list is empty!

            Comment


            • #7
              Re: ISO date to numeric YYYYMMDD

              The problem with the %char bif is that it truncates the leading zeros, which can be handy at times, and a pain as in this case.

              To do the same thing, but not truncate the zeros, you can use the %editc bif, and specify the 'X' edit code. It will take a number, such as the day of the month like the 9th, and display it as "09". With %char, you would get a single byte of "9".

              The beauty about rpgiv and date handling is that if you have a complex statement to handle some sort of date manipulation, there's probably a very quick shortcut to it.
              Michael Catalani
              IS Director, eCommerce & Web Development
              Acceptance Insurance Corporation
              www.AcceptanceInsurance.com
              www.ProvatoSys.com

              Comment


              • #8
                Re: ISO date to numeric YYYYMMDD

                Bryce,
                You do NOT need the *ISO to get YYYYMMDD if the H spec in your program is *ISO, which is the default date format used in RPG programs.

                If I run the program below
                PHP Code:
                h Option( *srcstmt: *nodebugio )            
                h DftActGrp( *no )                          
                                                            
                d tmpfdate        s              8p 0 inz   
                d fdate           s               d         
                                                            
                 
                /free                                      
                                                            
                  
                *inlr = *on;                              
                  
                fdate = %date();                          
                  
                tmpfdate = %dec(fdate);                   
                  
                dsply tmpfdate;                           
                  return; 
                I get 20090317 as required, not 03172009.

                You get MMDDYYYYinstead because you should have an H spec with DATFMT(*USA).
                I get YYYYMMDD since the default date format is *ISO.
                Philippe

                Comment


                • #9
                  Re: ISO date to numeric YYYYMMDD

                  bryce ...
                  Procedure - Getdate

                  you will need to remove the holiday logic...


                  Code:
                        * What is returned
                        * EVAL date
                        * DATE.ERROR = 'N'                  1
                        * DATE.ISO = '2007-08-01'           2-11
                        * DATE.MDY = '08/01/07'            12-19
                        * DATE.USA = '08/01/2007'          20-29
                        * DATE.ISO0 = 20070801.            30-37
                        * DATE.MDY0 = 080107.              38-43
                        * DATE.USA0 = 08012007.            44-51
                        * DATE.JUL0 = 2454314.             52-58
                        * DATE.DAYNAME = 'Wednesday'       59-67
                        * DATE.MONTHNAME = 'August   '     68-76
                        * DATE.LSTDAYCUR = '2007-08-31'    77-86
                        * DATE.LSTDAYCURISO = 20070831.    87-94
                        * DATE.LSTDAYCURMDY = 083107.      95-100
                        * DATE.LSTDAYCURCYMD = 1070831.   101-107
                        * DATE.FSTDAYCUR = '2007-08-01'   108-117
                        * DATE.FSTDAYCURISO = 20070801.   118-125
                        * DATE.FSTDAYCURMDY = 080107.     126-131
                        * DATE.FSTDAYCURCYMD = 1070801.   132-138
                        *
                        * DATE.LSTDAYLST = '2007-07-31'   139-148
                        * DATE.LSTDAYLSTISO = 20070731.   149-156
                        * DATE.LSTDAYLSTMDY = 073107.     157-162
                        * DATE.LSTDAYLSTCYMD = 1070731.   163-169
                        * DATE.FSTDAYLST = '2007-07-01'   170-179
                        * DATE.FSTDAYLSTISO = 20070701.   180-187
                        * DATE.FSTDAYLSTMDY = 070107.     188-193
                        * DATE.FSTDAYLSTCYMD = 1070701.   194-200
                        *
                        * DATE.STRING1 = '01 Aug 2007                   '   201-230
                        * DATE.STRING2 = 'Wednesday, 01 Aug 2007        '   231-260
                        * DATE.STRING3 = 'Wednesday, 01 August 2007     '   261-290
                        * DATE.TIME = '16.05.03'                            291-298
                        * DATE.TIMESTAMP = '2007-08-01-16.05.03.000000'     299-324
                        * DATE.WORKISO = '2007-07-01'                       325-334
                  
                  
                        * getdat  Format date into multiple formats
                  
                       d getdate         pr           512
                       d Indate                         8    const options(*nopass)
                       d Indays                         6  0 const options(*nopass)
                       d Inweekends                     1    const  options(*nopass)
                       d Inholidays                     1    const  options(*nopass)
                  
                        // the multiple formats of the date
                  
                       d date            ds                  qualified  inz
                       d  error                         1    inz('N')
                       d  iso                            d   datfmt(*iso)
                       d  mdy                            d   datfmt(*mdy)
                       d  usa                            d   datfmt(*usa)
                       d  iso0                          8  0
                       d  mdy0                          6  0
                       d  usa0                          8  0
                       d  jul0                          7  0
                       d  dayname                       9
                       d  monthname                     9
                       d  lstdaycur                    10
                       d  lstdaycuriso                  8  0
                       d  lstdaycurmdy                  6  0
                       d  lstdaycurcymd                 7  0
                       d  fstdaycur                    10
                       d  fstdaycuriso                  8  0
                       d  fstdaycurmdy                  6  0
                       d  fstdaycurcymd                 7  0
                       d  lstdaylst                    10
                       d  lstdaylstiso                  8  0
                       d  lstdaylstmdy                  6  0
                       d  lstdaylstcymd                 7  0
                       d  fstdaylst                    10
                       d  fstdaylstiso                  8  0
                       d  fstdaylstmdy                  6  0
                       d  fstdaylstcymd                 7  0
                       d  string1                      30
                       d  string2                      30
                       d  string3                      30
                       d  time                           t
                       d  timestamp                      z
                       d  workiso                        d   datfmt(*iso)
                  
                       d ds_Dayname      ds
                       d                                9    Inz('Sunday')
                       d                                9    Inz('Monday')
                       d                                9    Inz('Tuesday')
                       d                                9    Inz('Wednesday')
                       d                                9    Inz('Thursday')
                       d                                9    Inz('Friday')
                       d                                9    Inz('Saturday')
                       d arr_Dayname                    9    Dim(8) OverLay(ds_Dayname)
                  
                       d ds_monname      ds
                       d                                9    Inz('January')
                       d                                9    Inz('February')
                       d                                9    Inz('March')
                       d                                9    Inz('April')
                       d                                9    Inz('May')
                       d                                9    Inz('June')
                       d                                9    Inz('July')
                       d                                9    Inz('August')
                       d                                9    Inz('September')
                       d                                9    Inz('October')
                       d                                9    Inz('November')
                       d                                9    Inz('December')
                       d arr_monname                    9    Dim(12) OverLay(ds_monname)
                  
                       d CEEDAYS         pr                  opdesc
                       d   InputDate                65535A   const options(*varsize)
                       d   picture                  65535A   const options(*varsize)
                       d   Lilian                      10i 0
                       d   Feedback                    12a   options(*omit)
                  
                       d CEEDATE         pr                  opdesc
                       d   Lilian                      10i 0
                       d   picture                  65535A   const options(*varsize)
                       d   OutputDate               65535A   const options(*varsize)
                       d   Feedback                    12a   options(*omit)

                  then the meat
                  Code:
                       H NOMAIN EXPROPTS(*RESDECPOS)
                  
                        * PROGRAM - getdate
                        * PURPOSE - Subprocedure to format date into multiple formats
                        * WRITTEN - September 05 2007
                        * AUTHOR  - jamie flanary
                  
                  
                        * Parameters
                        *       Indate                Char   8   input
                        *       Insubdays             dec    6   input
                        *       Inweekends            Char   1   input  (Y=include weekends)
                        *       Inholidays            Char   1   input  (Y=include holidays)
                        *
                        *  if inweekends and/or inholidays not passed then default to "N"
                  
                        * Indicator Usage
                        *   None
                  
                        *   The getdatE_CP copy member should be used by programs that call this subprocedure
                        *   to obtain the procedure prototype fields.
                  
                  
                        /copy qprcsrc,getdate_cp
                  
                  
                       d a               s              5  0
                       d y               s              5  0
                       d m               s              5  0
                       d char10          s             10
                       d Dateinerror     s              1    inz('N')
                       d DayCount        s              6  0 inz
                       d DayOf           s              1  0 inz
                       d DayOfweek       s              1  0 inz
                       d decimal6        s              6  0 inz
                       d f1              s              7  0
                       d f2              s              7  0
                       d f3              s              7  0
                       d f4              s              7  0
                       d f5              s              7  0
                       d formatBack      s          65535A   varying
                       d holidaycount    s              6  0
                       d indate          s             10a
                       d Lilian          s             10i 0
                       d NewDate         s             52a
                       d outdate         s              8
                       d work6           s              6  0
                       d work7           s              7  0
                       d work8           s              8  0
                       d workIso         s               D
                       d workIso0        s              8  0
                       d workdate        s              8
                       d workdays        s              6  0
                       d workholidays    s              1
                       d workweekends    s              1
                        *
                  
                        * Begin Procedure
                       P getdate         B                   export
                  
                        * Procedure Interface
                       d getdate         pi           512
                       d indate                         8    const  options(*nopass)
                       d indays                         6  0 const  options(*nopass)
                       d inweekends                     1    const  options(*nopass)
                       d inholidays                     1    const  options(*nopass)
                  
                        /free
                  
                            Exec SQL set option datfmt= *iso;
                  
                  
                           //all parms are optional so check to see what was passed
                  
                           if %parms >= 1;
                            workdate = indate;
                           else;
                            clear workdate;
                           endif;
                  
                           if %parms >= 2;
                            workdays = indays;
                           else;
                            clear workdays;
                           endif;
                  
                           if %parms >= 3;
                            workweekends = inweekends;
                           else;
                            workweekends = 'N';
                           endif;
                  
                           if %parms >= 4;
                            workholidays = inholidays;
                           else;
                            workholidays = 'N';
                           endif;
                  
                           exsr $checkdate;
                  
                            // if valid date passed in (or *blanks) then process
                           if dateinerror = 'N';
                            if workdays <> *zeros;
                             exsr $checkdatemath;
                            endif;
                            exsr $formatdate;
                           endif;
                           date.error = 'N';
                           if dateinerror = 'Y';
                            date.error = 'Y';
                           endif;
                  
                           return date;
                  
                          //--------------------------------------------------------
                          // $checkdate - figure out what format the date is in
                          //              if format found then validate.
                          //--------------------------------------------------------
                               begsr $checkdate;
                  
                            // make sure that passed in parameter contains all digits (or blanks)
                  
                                if %check(' 0123456789 ': workdate) = 0;
                  
                            // get the length of workdate this will help determine
                            // what format the date is in if blank then workdate
                            // will be Today. ==> get date into *ISO format for the
                            // rest of the process.
                  
                                 reset dateinerror;
                                 workiso = *loval;
                                 select;
                                  when workdate = *blanks;
                                   workiso = %date();
                  
                                  when %len(%trim(workdate)) = 6;
                                   // *MDY or *YMD or *DMY
                                   work6 = %dec(workdate:6:0);
                                   test(de) *mdy  work6;
                                   if not%error;
                                    WorkIso = %date(work6:*mdy);
                                   else;
                                    test(de) *ymd  work6;
                                    if not%error;
                                     WorkIso = %date(work6:*ymd);
                                    else;
                                     test(de) *dmy  work6;
                                     if not%error;
                                      WorkIso = %date(work6:*dmy);
                                     else;
                                       // date is 6 in length but not valid
                                      dateinerror = 'Y';
                                     endif;
                                    endif;
                                   endif;
                  
                                  when %len(%trim(workdate)) = 7;
                                   // *cymd
                                   work7 = %dec(workdate:7:0);
                                   test(de) *cymd  work7;
                                   if not%error;
                                    WorkIso = %date(work7:*cymd);
                                   else;
                                    dateinerror = 'Y';
                                   endif;
                  
                                  when %len(%trim(workdate)) = 8;
                                   // *iso
                                   work8 = %dec(workdate:8:0);
                                   test(de) *iso  work8;
                                   if not%error;
                                    WorkIso = %date(work8:*iso);
                                   else;
                                    dateinerror = 'Y';
                                   endif;
                  
                                  other;
                                // date not in known format......
                                   dateinerror = 'Y';
                                 endsl;
                  
                                // date contains characters ......
                                else;
                                   dateinerror = 'Y';
                                endif;
                  
                               endsr;
                  
                          //--------------------------------------------------------
                          // $checkdatemath - check to see if user wants to add/sub
                          //                  days from passed in date also check
                          //                  to see if user wants to include
                          //                  weekends in date math.
                          //--------------------------------------------------------
                               begsr $checkdatemath;
                  
                                clear daycount;
                                dou daycount = %abs(workdays);
                  
                                  select;
                                   when workdays < *zeros;
                                    workiso -= %days(1);
                                   when workdays > *zeros;
                                    workiso += %days(1);
                                  endsl;
                  
                                 exec sql
                                 values dayofweek(:workiso) into :dayofweek;
                                 clear holidaycount;
                                 workiso0 = %dec(workiso:*iso);
                  
                                 exec sql select count(*)
                                          into :holidaycount
                                          from MSDHOLIDY
                                          where MDDATE   = : workiso0;
                  
                                 if workweekends = 'Y' or
                                    workweekends = 'N' and dayofweek <> 1 and
                                                           dayofweek <> 7;
                                  if workholidays = 'Y' or
                                     workholidays = 'N' and holidaycount = *zeros;
                  
                                   daycount +=1;
                  
                                  endif;
                                 endif;
                  
                                enddo;
                  
                               endsr;
                  
                          //--------------------------------------------------------
                          // $Formatdate - format the date into multiple formats
                          //--------------------------------------------------------
                               begsr $Formatdate;
                  
                            // okay start the manipulation
                  
                               date.iso  = workiso;
                  
                             // date 19390801 will validate as a "proper"
                             // date but when you try to move to *MDY well
                             // very bad things will happen.
                  
                               if %subdt(workiso:*years) < 1940;
                                char10 = %char(workiso:*iso);
                                decimal6 = %dec(%subst(char10:6:2)  +
                                           %subst(char10:9:2)  +
                                           %subst(char10:3:2):6:0);
                  
                                date.mdy = %date(decimal6:*mdy);
                               else;
                                date.mdy  = workiso;
                               endif;
                  
                               date.usa  = workiso;
                               date.iso0 = %dec(workiso:*iso);
                               date.mdy0 = %dec(date.mdy:*mdy);
                               date.usa0 = %dec(workiso:*usa);
                  
                               // julian date  - same date rules apply here
                               // 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
                  
                               if %subdt(workiso:*years) < 1940;
                  
                                 // 14 - months / 12
                                a = (14 - %subdt(workiso:*months)) / 12;
                                if a < 1;
                                 a = *zeros;
                                endif;
                  
                                 // year + 4800 - a
                                y = (%subdt(workiso:*years) + 4800) - a;
                  
                                 // month + 12(a) - 3
                                m = (%subdt(workiso:*months) + (12*a) - 3);
                  
                                f1 = (153*m + 2) / 5;
                                f2 = 365*y;
                                f3 = y/4;
                                f4 = y/100;
                                f5 = y/400;
                  
                                date.jul0 =
                                            %subdt(workiso:*days)  +
                                            f1                     +
                                            f2                     +
                                            f3                     -
                                            f4                     +
                                            f5                     -
                                            32045;
                  
                               else;
                               exec sql
                               values  julian_day(:date.iso) into :date.jul0 ;
                               endif;
                  
                               // get day of week
                               exec sql
                                values dayofweek(:date.iso) into :DayOf;
                  
                               date.dayname = Arr_Dayname(DayOf);
                  
                               // month name
                               date.monthname = Arr_monname(%subdt(date.iso:*months));
                  
                               // last day of current month
                               exec sql
                               set :date.lstdaycur = char(last_day(:date.iso), ISO);
                               // last day of current month decimal 8
                               date.lstdaycuriso  = %dec(%Date(date.lstdaycur): *Iso);
                  
                             // date 19390801 will validate as a "proper"
                             // date but when you try to move to *MDY well
                             // very bad things will happen.
                  
                               if %subdt(%date(date.lstdaycur:*iso):*years) < 1940;
                                char10 = %char(%date(date.lstdaycur));
                                decimal6 = %dec(%subst(char10:6:2)  +
                                           %subst(char10:9:2)  +
                                           %subst(char10:3:2):6:0);
                  
                                date.lstdaycurmdy = %dec(%date(decimal6:*mdy):*mdy);
                               else;
                                date.lstdaycurmdy  = %dec(%date(date.lstdaycur): *mdy);
                               endif;
                  
                               date.lstdaycurcymd = %dec(%Date(date.lstdaycur): *cymd);
                  
                               // first day of current month
                               workiso = date.iso - %days(%subdt(date.iso:*d)-1);
                               date.fstdaycur = %char(workiso);
                               // first day of current month decimal 8
                               date.fstdaycuriso  = %dec(%Date(date.fstdaycur): *Iso);
                  
                               if %subdt(%date(date.fstdaycur:*iso):*years) < 1940;
                                char10 = %char(%date(date.fstdaycur));
                                decimal6 = %dec(%subst(char10:6:2)  +
                                           %subst(char10:9:2)  +
                                           %subst(char10:3:2):6:0);
                  
                                date.fstdaycurmdy = %dec(%date(decimal6:*mdy):*mdy);
                               else;
                                date.fstdaycurmdy  = %dec(%Date(date.fstdaycur): *mdy);
                               endif;
                  
                               date.fstdaycurcymd = %dec(%Date(date.fstdaycur): *cymd);
                  
                               // last day of previous month
                               date.workiso = date.iso - %months(1);
                  
                               exec sql
                               set :date.lstdaylst = char(last_day(:date.workiso), ISO);
                               date.lstdaylstiso  = %dec(%Date(date.lstdaylst): *Iso);
                  
                               if %subdt(%date(date.lstdaylst:*iso):*years) < 1940;
                                char10 = %char(%date(date.lstdaylst));
                                decimal6 = %dec(%subst(char10:6:2)  +
                                           %subst(char10:9:2)  +
                                           %subst(char10:3:2):6:0);
                  
                                date.lstdaylstmdy = %dec(%date(decimal6:*mdy):*mdy);
                               else;
                                date.lstdaylstmdy  = %dec(%date(date.lstdaylst): *mdy);
                               endif;
                  
                               date.lstdaylstcymd = %dec(%Date(date.lstdaylst): *cymd);
                  
                               // first day of previous month
                               date.workiso = date.iso - %months(1);
                               workiso = date.workiso - %days(%subdt(date.workiso:*d)-1);
                               date.fstdaylst = %char(workiso);
                               date.fstdaylstiso  = %dec(%Date(date.fstdaylst): *Iso);
                  
                               if %subdt(%date(date.fstdaylst:*iso):*years) < 1940;
                                char10 = %char(%date(date.fstdaylst));
                                decimal6 = %dec(%subst(char10:6:2)  +
                                           %subst(char10:9:2)  +
                                           %subst(char10:3:2):6:0);
                  
                                date.fstdaylstmdy = %dec(%date(decimal6:*mdy):*mdy);
                               else;
                                date.fstdaylstmdy  = %dec(%Date(date.fstdaylst): *mdy);
                               endif;
                  
                               date.fstdaylstcymd = %dec(%Date(date.fstdaylst): *cymd);
                  
                               // build a date string
                               CEEDAYS(%char(date.iso): 'YYYY-MM-DD': lilian: *omit);
                               CEEDATE(Lilian: 'DD Mmm YYYY': NewDate: *omit);
                               date.string1 = newdate;
                                // this ===> 24 Jun 2007
                  
                               formatBack = 'Wwwwwwwwwz, DD Mmm YYYY';
                               CEEDATE(Lilian: Formatback : NewDate: *omit);
                               date.string2 = newdate;
                                // this ===> Wednesday, 27 Jun 2007
                  
                               formatBack = 'Wwwwwwwwwz, DD Mmmmmmmmmz YYYY';
                               CEEDATE(Lilian: Formatback : NewDate: *omit);
                                // this ===> Wednesday, 27 June 2007
                               date.string3 = newdate;
                  
                               // get timestamp
                               date.time = %time();
                               exec sql
                               values timestamp(:date.iso,:date.time) into :Date.timestamp;
                  
                               endsr;
                  
                          //--------------------------------------------------------
                        /end-free
                  
                       p getdate         E


                  to test

                  Code:
                        // crtpgm getdattst module(getdattst getdate)
                  
                        /copy qprcsrc,getdate_CP
                  
                       d indate          s              8
                        * ================================================
                        * M A I N   L I N E
                        * ================================================
                        *
                        /free
                  
                             indate = '090507';
                             date = getdate(indate: -8 :'N');
                  
                             indate = '20071120';
                             date = getdate(indate : 5);
                  
                             date = getdate();
                  
                         *inlr = *on;
                        /end-free
                        *
                  Attached Files
                  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


                  • #10
                    Re: ISO date to numeric YYYYMMDD

                    Well, Nice program Jamie

                    Mercury, I will have to disagree with you because here is my H-specs

                    Code:
                         H DEBUG  OPTION( *SRCSTMT: *NODEBUGIO )
                         H EXPROPTS(*RESDECPOS)
                         H BNDDIR('CSSRVPGM')
                         H DFTACTGRP(*NO)
                         H ACTGRP('PNS054')
                    Now, the field I'm operating on is a display file field and it has DATFMT(*USA)... would that do the same thing?
                    Your future President
                    Bryce

                    ---------------------------------------------
                    http://www.bravobryce.com

                    Comment


                    • #11
                      Re: ISO date to numeric YYYYMMDD

                      yep Bryce, by all means !
                      Philippe

                      Comment


                      • #12
                        Re: ISO date to numeric YYYYMMDD

                        WebSphere Development StudioILE RPG Language Reference Version 6, Release 1 SC09-2508-07

                        page 497: %dec

                        Date, time or timestamp expression

                        When the first parameter is a date time or timestamp expression,
                        the optional format parameter specifies the format of the value returned.

                        The converted decimal value will have the number of digits that a value of that format can have, and zero decimal positions.

                        For example, if the first parameter is a date, and the format is *YMD, the decimal value will have six digits.

                        If the format parameter is omitted, the format of the first parameter is used.


                        See ?DATFMT(fmt{separator})? on page 260 and ?TIMFMT(fmt{separator})? on page 273.

                        Format *USA is not allowed with a time expression.

                        If the first parameter is a time value with a time-format of *USA,
                        the second format parameter for %DEC must be specified.
                        Code:
                        D yyddd 	S 		 5S 0 
                        D yyyymmdd 	S 		 8P 0 
                        D hhmmss 	S 		 6P 0 
                        D numeric 	S 		20S 0 
                        D date 		S 		  D   inz(D?2003-06-27?) DATFMT(*USA) 
                        D time 		S 		  T   inz(T?09.25.59?) 
                        D timestamp 	S 		  Z   inz(Z?2003-06-27-09.25.59.123456? 
                        
                         /free 
                        
                         // Using the format of the first parameter 
                        
                         numeric = %dec(date);      // numeric = 06272003 
                         numeric = %dec(time);      // numeric = 092559 
                         numeric = %dec(timestamp); // numeric = 20030627092559123456 
                        
                         // Using the second parameter to specify the result format 
                        
                         yyddd    = %dec(date : *jul); // yyddd    = 03178 
                         yyyymmdd = %dec(date : *iso); // yyyymmdd = 20030627

                        Comment


                        • #13
                          Re: ISO date to numeric YYYYMMDD

                          Very well explained Marc. Thank you.
                          Your future President
                          Bryce

                          ---------------------------------------------
                          http://www.bravobryce.com

                          Comment


                          • #14
                            Re: ISO date to numeric YYYYMMDD

                            Reminds me a bit of the complicators gloves.

                            It's a particularly busy week for me: on top of a few looming deadlines, I'll be at Business of Software 2008 in Boston. So, I figured it'd be the perfect opportunity to revisit some classics. The Complicator's Gloves was originally published on January 16th, 2007. Another fun, tangentially related article is The Complicator's Bicycle.


                            That's a good IT blog btw with lot's of articles on programming bloopers.
                            Ben

                            Comment


                            • #15
                              Re: ISO date to numeric YYYYMMDD

                              Philippe

                              Comment

                              Working...
                              X