× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Peter,

find enclosed some snippets, I collected in the past for date operations in
FREE-Format:

D #TmStmp         S               Z                  
D #TodayDate      S               D   DatFmt(*ISO)   
D #TodayTime      S               T   TimFmt(*HMS)   
D #DateEUR        S               D   DatFmt(*EUR)   
D #DateISO        S               D   DatFmt(*ISO)   
D #TimeISO        S               T   TimFmt(*ISO)   
                                                     
D #DatNumEUR      S              8S 0 Inz(22032001)  
D #DatNumISO      S              8S 0                
D #DatNum6        S              6S 0                
D #DatNum7        S              7S 0                
D #TimNum         S              6S 0 Inz(113614)    
                                                     
D #CharDate       S              8A   Inz('20020322')
D #CharTime       S              6A   Inz('113614')  
D #CharDate10     S             10A                  
                                        
 D FldChar6        S              6A    
 D FldChar7        S              7A    
 D FldChar8        S              8A    
 D FldChar9        S              9A    
 D FldChar10       S             10A    
 D FldChar14       S             14A    
 D FldNum3         S              3S 0  
 D FldNum4         S              4S 0  
 D FldNum6         S              6S 0  
 D FldNum7         S              7S 0  
 D FldNum8         S              8S 0  
 D FldPack20       S             20P 0  
                                        
 D #CurCY          S              4S 0  
 D #CurMon         S              2S 0  
 D #CurDay         S              2S 0  
 D #Hours          S             10S 0  
 D #Minutes        S              2S 0  
 D #Seconds        S              2S 0  
D #NumYears       S             11S 0                        
D #NumMonth       S             11S 0                        
D #NumDays        S             11S 0                        
D #NumHours       S             11S 0                        
D #NumMinutes     S             11S 0                        
D #NumSeconds     S             11S 0                        
                                                             
D                 DS                                         
D $StrTmStmp                      Z   Inz                    
D  #StrDate                       D   Overlay($StrTmStmp:1)  
D  #StrTime                       T   Overlay($StrTmStmp:12) 
D                 DS                                         
D $EndTmStmp                      Z   Inz                    
D  #EndDate                       D   Overlay($EndTmStmp:1)  
D  #EndTime                       T   Overlay($EndTmStmp:12) 
                                                             
D #Diff                         10I 0                        
                                                             
D $TimDiff        DS                                         
D  #DiffHours                    7S 0                        
D  #DiffMinutes                  2S 0                                
D  #DiffSeconds                  2S 0                                
                                                                     
 *---------------------------------------------------------------    
 /free                                                               
                                                                     
   // Retrieve current date                                          
   #TodayDate=%date();                                               
                                                                     
   // Convert numeric field into date field                          
   #DatNumISO=20020325;                                              
   #DateISO=%date(#DatNumISO:*iso);                                  
                                                                     
   // Convert character field into date field                        
   #CharDate='20020325';                                             
   #DateISO=%date(#CharDate:*iso0);                                  
                                                                     
   // Convert character field with date into numeric field with date 
   FldChar6='080303';                                                
   #DatNumISO=%int(%char(%date(FldChar6:*dmy0):*iso0));              
                                                                  
  // Convert numeric field with date into numeric field with date 
  #DatNumISO=20030315;                                            
  #DatNum6=%int(%char(%date(#DatNumISO:*iso):*dmy0));             
  #DatNum6=%int(%char(%date(#DatNumISO:*iso):*ymd0));             
                                                                  
  #DatNum7=1030704;                                               
  #DatNum6=%int(%char(%date(#DatNum7:*cymd):*dmy0));              
                                                                  
  // Convert character field to date field                        
  #CharDate10='2002-03-25';                                       
  #DateISO=%date(#CharDate10:*iso);                               
                                                                  
  // Convert current date to numeric field                        
  #DatNumISO=%int(%char(%date():*iso0));                          
                                                                  
  // Convert date field to numeric field                          
  #DatNumISO=%int(%char(#DateISO:*iso0));                         
  #DatNum6=%int(%char(#DateISO:*dmy0));                           
  #DatNum7=%int(%char(#DateISO:*cymd0));                          
                                                                   
  // Convert date field to character field with separator .        
  FldChar8=%char(#DateISO:*dmy.);                                  
                                                                   
  // Retrieve day of year into numeric field (from given date)     
  #DateISO=%date('20030725':*iso0);                                
  FldNum3=%int(%subst(%char(#DateISO:*jul0):3:3));                 
                                                                   
  // Retrieve day of year into numeric field (from current date)   
  FldNum3=%int(%subst(%char(%date():*jul0):3:3));                  
                                                                   
  // Retrieve current time                                         
  #TodayTime=%time();                                              
                                                                   
  // Convert current time numeric field                            
  #TimNum=%int(%char(%time():*iso0));                              
                                                                   
  // Convert current time numeric field (only HHMM)                
  FldNum4 = %int(%subst(%char(%time():*iso0):1:4));                
  // Convert numeric field into time field                         
  #TodayTime=%time(#TimNum:*iso);                                           
                                                                            
  // Convert character field into time field                                
  #TodayTime=%time(#CharTime:*iso0);                                        
                                                                            
  // Create individual timestamp. Example: DDMMHHMMSS                       
  FldChar10 = %subst(%triml(%editw(%subdt(%date():*D):'0         ')):       
              8:2) +                                                        
              %subst(%triml(%editw(%subdt(%date():*M):'0         ')):       
              8:2) +                                                        
              %subst(%triml(%editw(%int(%char(%time():*iso0)):              
              '0         ')):4:6);                                          
                                                                            
  // Add 3 days to #DatNum7 and convert the result to #DatNumISO            
  #DatNumISO = %int(%char(%date(#DatNum7:*cymd) + %days(3):*iso0));         
                                                                            
  // Add 3 days to current date and convert the result to a character field 
  FldChar8 = %char(%date() + %days(3):*iso0);                               
                                                                            
  // Add seconds to a numeric field                                         
   #TimNum = %int(%char(%time(#TimNum:*iso) + %seconds(1):*iso0));

 

   // Retrieve current timestamp

   #TmStmp=%timestamp();

 

   // Retrieve string YYYYMMDDHHMMSS from current timestamp

   FldChar14 = %subst(%char(%timestamp:*iso0):1:14);

 

   // Retrieve full timestamp into numeric field (Resultfield must be
packed) 
   FldPack20 = %dec(%char(%timestamp():*iso0):20:0);

 

   // Date/Time codes: *YEARS(*Y), *MONTHS(*M), *DAYS(*D), *HOURS(*H),

   //                  *MINUTES(*MN), *SECONDS(*S), *MSECONDS(*MS)

 

   // Extract year/month/day from date field

   #CurCY =%subdt(#TodayDate:*Y);

   #CurMon=%subdt(#TodayDate:*M);

   #CurDay=%subdt(#TodayDate:*D);

 

   // Extract hours/minutes/seconds from time field

  #Hours  =%subdt(#TodayTime:*H);                    
  #Minutes=%subdt(#TodayTime:*MN);                   
  #Seconds=%subdt(#TodayTime:*S);                    
                                                     
  // Add/subtract years, months, days to date field  
  #DateISO=#DateISO+%years(1);                       
  #DateISO=#DateISO+%months(6);                      
  #DateISO=#DateISO+%days(30);                       
                                                     
  #DateISO=#DateISO-%years(1);                       
  #DateISO=#DateISO-%months(6);                      
  #DateISO=#DateISO-%days(30);                       
                                                     
  // Add/subtract hours, minutes, seconds            
  #TimeISO=#TimeISO+%hours(1);                       
  #TimeISO=#TimeISO+%minutes(15);                    
  #TimeISO=#TimeISO+%seconds(10);                    
                                                     
  #TimeISO=#TimeISO-%hours(1);                       
  #TimeISO=#TimeISO-%minutes(15);                    
  #TimeISO=#TimeISO-%seconds(10);            
                                             
  // Calculate date and time differences     
  #NumYears=%diff(#TodayDate:#DateISO:*Y);   
  #NumMonth=%diff(#TodayDate:#DateISO:*M);   
  #NumDays =%diff(#TodayDate:#DateISO:*D);   
                                             
  #NumHours   =%diff(#TodayTime:#TimeISO:*H);
  #NumMinutes =%diff(#TodayTime:#TimeISO:*MN)
  #NumSeconds =%diff(#TodayTime:#TimeISO:*S);
                                             
  // Test valid date in numeric fields       
  FldNum8=20020325;                          
  test(de) *iso FldNum8;                     
  if %error;                                 
  // . . .                                   
  endif;                                     
                                             
  FldNum7=1020325;                           
  test(de) *cymd FldNum7;                    
  if %error;                             
  // . . .                               
  endif;                                 
                                         
  FldNum6=250302;                        
  test(de) *dmy FldNum6;                 
  if %error;                             
  // . . .                               
  endif;                                 
                                         
  // Test valid date in character fields 
  FldChar10='2002-03-25';                
  test(de) *iso FldChar10;               
  if %error;                             
  // . . .                               
  endif;                                 
                                         
  FldChar8='20020325';                   
  test(de) *iso0 FldChar8;               
  if %error;                             
  // . . .                  
  endif;                    
                            
  FldChar9='102/03/25';     
  test(de) *cymd FldChar9;  
  if %error;                
  // . . .                  
  endif;                    
                            
  FldChar7='1020325';       
  test(de) *cymd0 FldChar7; 
  if %error;                
  // . . .                  
  endif;                    
                            
  FldChar8='25/03/02';      
  test(de) *dmy FldChar8;   
  if %error;                
  // . . .                  
  endif;                    
                                          
  FldChar6='250302';                      
  test(de) *dmy0 FldChar6;                
  if %error;                              
  // . . .                                
  endif;                                  
                                          
  // Test valid time in numeric fields    
  FldNum6=103521;                         
  test(te) *iso FldNum6;                  
  if %error;                              
  // . . .                                
  endif;                                  
                                          
  // Test valid time in character fields  
  FldChar6='103521';                      
  test(te) *iso0 FldChar6;                
  if %error;                              
  // . . .                                
  endif;                                  
                                                                  
  // Calculate time difference between start- and end date/time.  
  //   Result fields are contained in DS $TimDiff                 
  #EndDate=%date(20031011:*iso);                                  
  #EndTime=%time(060000:*iso);                                    
  #StrDate=%date(20031008:*iso);                                  
  #StrTime=%time(000000:*iso);                                    
                                                                  
  #Diff = %diff($EndTmStmp:$StrTmStmp:*seconds);                  
  #DiffHours   = #Diff/3600;                                      
  #DiffMinutes = (#Diff - #DiffHours * 3600) / 60;                
  #DiffSeconds =  #Diff - #DiffHours * 3600 - #DiffMinutes * 60;  
                                                                  
  // Retrieve date of last day of a month                         
  #TodayDate = %date(); // Example                                
  #DateISO = (#TodayDate + %months(1)) -                          
             %days(%subdt(#TodayDate + %months(1):*D));           
                                                                  
  Return;                                                         
/end-free                                                         

Hope this helps!

Regards,
GEFIS Gesellschaft für
Individual-Software mbH
Werner Noll

-----Ursprüngliche Nachricht-----
Von: Peter Colpaert [mailto:Peter.Colpaert@xxxxxxxxxxxx]
Gesendet: Dienstag, 29. Juli 2003 11:12
An: RPG400-L@xxxxxxxxxxxx
Betreff: Date conversion




Hi group,

I have a procedure that takes in an 8s 0 date in YYYYMMDD format and
returns the same date in DDMMYYYY format, and have converted it from fixed
to free format.

This is the code I came up with, but my gut feeling tells me there must be
a better and more elegant way.

     p IsoEuro         b                   export
     d IsoEuro         pi             8s 0
     d DateNum                        8s 0 value
     d AtoI            PR            10i 0 ExtProc('atoi')
Alpha to Integer
     d                                 *   value options(*string)
      //
      /FREE
       return atoi(%subst(%char(%date(DateNum:*ISO):*EUR):1:2)
                   %subst(%char(%date(DateNum:*ISO):*EUR):4:2)
                   %subst(%char(%date(DateNum:*ISO):*EUR):7:4));
       //
      /END-FREE
     p IsoEuro         e

Can anybody point me in the right direction?

Thanks in advance.

Peter Colpaert
Application Developer

Honda Europe NV
Langerbruggestraat 104
B-9000 GENT
Belgium
Peter.Colpaert@xxxxxxxxxxxx
Tel: +32 9 2501 334
Fax: +32 9 2501 231
----------
Yoda of Borg are we: Futile is resistance. Assimilate you, we will.
----------



______________________________________________________________________
The information contained in this communication is confidential and may be
legally privileged. It is intended solely for the use of the individual or
the entity to whom it is addressed and others authorised to receive it. If
you have received it by mistake, please let the sender know by e-mail reply
and delete it from your system.
If you are not the intended recipient you are hereby notified that any
disclosure, copying, distribution or taking any action in reliance of the
contents of this information is strictly prohibited and may be unlawful.
Honda Europe NV is neither liable for the proper and complete transmission
of the information contained in this communication nor for any delay in its
receipt.



_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.