Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

converting unix (epoch) time in rexx

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
Deborah Shugerts

New User


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

PostPosted: Thu Oct 29, 2009 2:07 am    Post subject: converting unix (epoch) time in rexx
Reply with quote

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 ?
Back to top
View user's profile Send private message

Deborah Shugerts

New User


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

PostPosted: Thu Oct 29, 2009 2:48 am    Post subject: Reply to: converting unix (epoch) time in rexx
Reply with quote

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
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Oct 29, 2009 3:59 am    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
Deborah Shugerts

New User


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

PostPosted: Thu Oct 29, 2009 5:00 pm    Post subject:
Reply with quote

Thanks to all for your help !
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Oct 29, 2009 6:21 pm    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Oct 29, 2009 7:42 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Thu Oct 29, 2009 8:32 pm    Post subject:
Reply with quote

Thanks Dick, always nice to know that ones efforts are sometimes appreciated icon_lol.gif
Back to top
View user's profile Send private message
Deborah Shugerts

New User


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

PostPosted: Thu Oct 29, 2009 11:38 pm    Post subject:
Reply with quote

Thx to both of you too (expat and dick) ! Really appreciate all your help with this !
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Need help on If condition continuatio... ashok_uddaraju CLIST & REXX 4 Fri May 19, 2017 8:55 am
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts DSNACCOX (can it be run on 1 db/ts, t... SRICOBSAS DB2 3 Sat May 06, 2017 12:59 am
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts Running an REXX EXEC implicitly sho7hills CLIST & REXX 3 Thu Apr 20, 2017 8:14 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us