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 Roblumley120 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
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.
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.
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)
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
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.)
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.
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:
or alternatively multiply the millisecond input and then add a *MS duration.
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)
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)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 eUTC 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