Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6970
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: 8620
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: 6970
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: 8620
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
No new posts Looping REXX - unable to interrupt RAVISANKAR07 CLIST & REXX 3 Wed Dec 06, 2017 1:08 pm
No new posts The same REXX program doesnt work for... jackzhang75 CLIST & REXX 5 Wed Dec 06, 2017 2:51 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm
This topic is locked: you cannot edit posts or make replies. Rexx to Grab ISMF Information. upendrasri All Other Mainframe Topics 16 Sun Nov 26, 2017 12:35 am
No new posts Rexx to send an email without SMTP Se... upendrasri All Other Mainframe Topics 12 Sun Nov 19, 2017 7:59 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us