|
The date/time stamp is in seconds since 00:00:00 January 1 1601 like 127122881993040000. Anyone know how to translate the number of seconds elapsed since 00:00:00, January 1, 1601, to a date and time?
The sample number you've provided does not make sense. That number is waaaaaay too high to be a number of seconds. That number equates to approximately 4028281047 years. (Take a calculator and divide it by 60 to get minutes, 60 again to get hours, 24 to get days, and 365.25 to get a number of years. The result will be 4028281047.)
Since 1601 was only 406 years ago, that number can't possibly be a number of seconds. (Unless your users can time travel to 4 billion years in the future.)
That being the case, I fired up Google and did some searching to try to find out what that number really means. I found the following post, which was very helpful:
http://tinyurl.com/y5jhllThe post says "First off the 64 bit Integer Time Values (Called Integer8) represents the number of 100 nanosecond intervals between the time stamp and January 1, 1601." That makes a lot more sense -- and should make it quite easy to calculate in RPG. Just divide by 10 million to get a number of seconds, then use the date/time operations to convert it to a timestamp.
Here's some fixed-format RPG code that converts from that timestamp to an RPG timestamp field:
D StartPoint c z'1601-01-01-00.00.00.000000' D AD_Time s 20u 0 inz(127122881993040000) D Result s Z C div 10000000 AD_Time C StartPoint adddur AD_Time:*S ResultNot so tough when you know what the number means :) Of course, I'd prefer to do it in free format.. so here's the same thing in free format.
D StartPoint c z'1601-01-01-00.00.00.000000' D AD_Time s 20u 0 inz(127122881993040000) D Result s Z /free Result = StartPoint + %seconds(%div(AD_TIME:10000000));The next question is "What time zone is that time stamp in?". That poist doesn't explcitly say, but they tell you how to convert the timestamp so that it'll be compatible with the localtime(), gmtime() and ctime() C functions. Since I also do programming in C, I know that those 3 functions take their input in Universal Time Coordinated (UTC) rather than in the computer's local time.
The ILE environment provides an API called CEEUTCO that will provide (among other things) the number of seconds difference between your system's current (local) time, and UTC. You could add that number to the timestamp to give you a timestamp that's in the local time zone.
For example, you could do this: H DFTACTGRP(*NO) D CEEUTCO PR opdesc D Hours 10I 0 D Minutes 10I 0 D Seconds 8F D Feedback 12a options(*omit) D StartPoint c z'1601-01-01-00.00.00.000000' D AD_Time s 20u 0 inz(127122881993040000) D Result s Z D junk1 s 10I 0 D junk2 s 10I 0 D seconds s 8F /free // Get the number of seconds between local time // and UTC time. CEEUTCO( junk1: junk2: seconds: *omit); Result = StartPoint + %seconds(%div(AD_TIME:10000000)) + %seconds(%int(seconds));After this code has run, if you display the time stamp value, you'll see the value as a "sensible" number. I live in the US Central time zone, which is 6 hours earlier than UTC time. When I run the preceding code, I get a timestamp of 2003-11-02-17.09.59.000000.
Of course, you (or someone else reading this) may want your date/time in numeric fields instead of a timestamp field. If that's the case, you can do the following to convert it to a number. (Requires V5R2)
Date8 = %int(%char(%date(Result):*ISO0)); Time6 = %int(%char(%time(Result):*HMS0));Okay, I'll stop trying to anticipate your future questions now :) But, if you have some, please ask...
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.