5 pts.
 UTC format which is basically the number of milliseconds since Jan 1 1970 convert in RPG
Is there a straightforward way using rpg ile to convert the UTC date into ymd format

Software/Hardware used:
ASKED: November 27, 2007  8:54 AM
UPDATED: March 2, 2010  7:31 AM

Answer Wiki:
This will convert 1074528964 milliseconds to 04/01/19 D unixts s 10U 0 inz(1074528964) D epoch s z inz(z'1970-01-01-00.00.00') D ts s z DYmd s D DATFMT(*YMD) c epoch adddur unixts:*S ts c move ts Ymd c dsply Ymd c eval *inlr = *on
Last Wiki Answer Submitted:  November 27, 2007  9:37 am  by  Roblumley   120 pts.
All Answer Wiki Contributors:  Roblumley   120 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

There’s something “funny” going on here. The Unix epoch is based on the number of seconds since Jan 1 1970 and not the number of milliseconds. The provided answer then correctly shows how to use seconds since the epoch, but is worded within the context of milliseconds (as is the original question).

If you really want milliseconds since Jan 1 1970 you should use the *MS duration code on the ADDDUR rather than *S. But I suspect that the use of milliseconds in the question and answer should really be rephrased to seconds.

 6,055 pts.

 

Oops! *MS is microseconds, not milliseconds. For a millisecond input you would need to divide the millisecond value by 1000 to get seconds and then add that duration to Epoch:

dSeconds          s             10u 0  

c                   eval      Seconds = MS/1000      
c     Epoch         adddur    Seconds:*S    TS       

or alternatively multiply the millisecond input and then add a *MS duration.

 6,055 pts.

 

for seconds

d date1 s 8a
d UTC s 10i 0 inz(1074528964)
d UTCBase s z inz(z’1970-01-01-00.00.00.000000′)

c eval date1 = %char(
c %date(UTCBase + %seconds(UTC))
c :*ymd)

for milliseconds
d date1 s 8a
d UTC s 10i 0 inz(1074528964)
d UTCBase s z inz(z’1970-01-01-00.00.00.000000′)

c eval date1 = %char(
c %date(UTCBase + %seconds(UTC/1000))
c :*ymd)

 7,175 pts.

 
d  date1          s              8a                                       
d  UTC            s             10i 0 inz(1074528964)                     
d  UTCBase        s               z   inz(z'1970-01-01-00.00.00.000000')  
                                                                          
c                   eval      date1 = %char(                              
c                                     %date(UTCBase + %seconds(UTC))      
c                                     :*ymd)                              
 7,175 pts.

 

OK, just had to make some procedures for this assuming seconds since 1/1/70

     h dftactgrp(*no) actgrp(*caller) indent('|') option(*srcstmt:*nodebugio)

     d  date1          s               d
     d  UTC1           s             10i 0

     d UTC2Date        pr              d
     d  inUTC                        10i 0 const
     d Date2UTC        pr            10i 0
     d  inDate                         d   const

     c                   eval      date1 = UTC2Date(1074528964)
     c                   eval      UTC1 = Date2UTC(%date('2004-01-19'))
     c                   dump(a)
     c                   eval      *inlr = *on

     p UTC2Date        b
     d UTC2Date        pi              d
     d  inUTC                        10i 0 const
     c                   return    %date(%timestamp(
     c                             '1970-01-01-00.00.00.000000')
     c                             + %seconds(inUTC))
     p UTC2Date        e

     p Date2UTC        b
     d Date2UTC        pi            10i 0
     d  inDate                         d   const
     c                   return    %diff(inDate:%date('1970-01-01'):*days)
     c                             * 24 * 60 * 60
     p Date2UTC        e
 7,175 pts.

 

UTC also may need consideration for system value QUTCOFFSET. It’s not clear from the question if a UTC value should simply be converted to a straight “ymd format” or if the intention is to convert a UTC value to the local “ymd format. The two can give different dates in many cases. ( I guess half the cases, depending on what time it is and what the local offset is.)

Tom

 107,845 pts.