## UTC format which is basically the number of milliseconds since Jan 1 1970 convert in RPG

5 pts.
Tags:
AS/400
RPG ILE
Is there a straightforward way using rpg ile to convert the UTC date into ymd format

## Answer Wiki

Thanks. We'll let you know when a new response is added.

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

## Discuss This Question: 6 Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
• 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,990 pointsBadges:
report
• 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,990 pointsBadges:
report
• 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)
8,550 pointsBadges:
report
• ```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)                              ```
8,550 pointsBadges:
report
• 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
```
8,550 pointsBadges:
report
• 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
125,585 pointsBadges:
report