Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
Deborah Shugerts

New User

Joined: 14 Oct 2009
Posts: 10
Location: A Florida Cubicle...

 Posted: Thu Oct 29, 2009 2:07 am    Post subject: converting unix (epoch) time in rexx Has anyone tried to convert UNIX (epoch) time into MM/DD/YY and HH:MM:SS format ? For example, 1256651712 equates to 10/27/09 13:55:12 (UTC). I know that 1256651712 equates to the # of seconds since midnight 1-1-1970. I can determine that 1256651712 is 14,544 days 13 hours 55 minutes 12 seconds since midnight 1-1-1970. So I know the time is 13:55:12. I suppose I can start dividing 14,544 by 365 to determine the # of years ago. But is there an easier way ?

Deborah Shugerts

New User

Joined: 14 Oct 2009
Posts: 10
Location: A Florida Cubicle...

 Posted: Thu Oct 29, 2009 2:48 am    Post subject: Reply to: converting unix (epoch) time in rexx I have worked out the basic code, but my julian date is off. I suspect leap years are the culprit. /* rexx */ epoch = 1256651712 epochdays = 1256651712 % 86400 epochrem = epoch - (epochdays*86400) epochhrs = epochrem % 3600 epochrem2 = epochrem - (epochhrs*3600) epochmin = epochrem2 % 60 epochsec = epochrem2 - (epochmin*60) epochyrs = epochdays % 365 daysleftover = epochdays - (epochyrs * 365) thisyr = 1970 + epochyrs jdate = substr(thisyr,3,2) || daysleftover newdate = left(Date('U',jdate,'J'),8) epochyrs = epochdays % 365 daysleftover = epochdays - (epochyrs * 365) thisyr = 1970 + epochyrs jdate = substr(thisyr,3,2) || daysleftover newdate = left(Date('U',jdate,'J'),8) say epochdays 'days since midnite 1-1-1970' say 'Date is 'newdate say 'Time is 'epochhrs':'epochmin':'epochsec Time is 13:55:10 14544 days since midnite 1-1-1970 Date is 11/05/09 Time is 13:55:10 Date returned should be 10/27/09 13:55:10
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

 Posted: Thu Oct 29, 2009 3:59 am    Post subject: a leapgrp is the number of days in a 4 year span - 3 normal 1 leap leapgrp = ((365 * 3) + 366) if you integer divide that into your number of days, that will tell you how many leapgrp's or the number of extra days that you did not allow for when dividing days by 365. numtoomanydays = numdays % leapgrp so the following is over by numtoomanydays (yeah I know, too long a reference name daysleftover = epochdays - (epochyrs * 365) - numtoomanydays
Deborah Shugerts

New User

Joined: 14 Oct 2009
Posts: 10
Location: A Florida Cubicle...

 Posted: Thu Oct 29, 2009 5:00 pm    Post subject: Thanks to all for your help !
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

Posted: Thu Oct 29, 2009 6:21 pm    Post subject:

Don't know if this is easier for you, letting the REXX date function take care of leap years from 1970 onwards and this code also copes with the 100 and 400 year anomolies.
 Code: /* REXX *** EPOCH TIME TO CURRENT TIME                               */ NUMERIC DIGITS 31 EPOCH   = 1256651712 DAYS    = TRUNC(EPOCH / (3600 * 24)) REMAIN  = EPOCH - (DAYS * 24 * 3600) BASEREX = DATE('B',19700101,'S') BASEREX = BASEREX + DAYS NEWDATE = DATE('S',BASEREX,'B') HH = 0 MM = 0 SS = 0 DO FOREVER   IF REMAIN >= 3600 THEN DO     REMAIN = REMAIN - 3600     HH = HH + 1   END   ELSE DO     IF REMAIN >= 60 THEN DO       REMAIN = REMAIN - 60       MM = MM + 1     END     SS = REMAIN     IF SS < 60 THEN LEAVE      END                        END                          SAY NEWDATE  HH MM SS

Resule is
 Code: 20091027 13 55 12
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

Posted: Thu Oct 29, 2009 7:42 pm    Post subject:

I am never shy about using code from others that works:
 Code: /* REXX *** EPOCH TIME TO CURRENT TIME                               */ /*  from expat  */ NUMERIC DIGITS 31 EPOCH   = 1256651712 DAYS    = TRUNC(EPOCH / (3600 * 24)) REMAIN  = EPOCH - (DAYS * 24 * 3600) say "Remain " remain BASEREX = DATE('B',19700101,'S') BASEREX = BASEREX + DAYS NEWDATE = DATE('S',BASEREX,'B') /*  from deborah  */ HH = remain % 3600 remain2 = remain - (HH*3600) MM = remain2 % 60 SS = remain2 - (MM*60) SAY NEWDATE  HH MM SS

Result: 20091027 13 55 12

Thx to both Expat and Deborah for something new.
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

 Posted: Thu Oct 29, 2009 8:32 pm    Post subject: Thanks Dick, always nice to know that ones efforts are sometimes appreciated
Deborah Shugerts

New User

Joined: 14 Oct 2009
Posts: 10
Location: A Florida Cubicle...

 Posted: Thu Oct 29, 2009 11:38 pm    Post subject: Thx to both of you too (expat and dick) ! Really appreciate all your help with this !
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Comparing 2 Files using Current time arunsoods DFSORT/ICETOOL 3 Fri Sep 22, 2017 6:00 pm ejck thru rexx to multiple jobs insid... Susanta All Other Mainframe Topics 5 Tue Sep 19, 2017 1:39 pm Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am Creating ISPF Screens with Scrname vi... Albireo20 TSO/ISPF 9 Tue Sep 05, 2017 4:24 pm Regarding time parameter shanthi gude JCL & VSAM 7 Mon Sep 04, 2017 2:31 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us