Converting Hundred Year Date Plus Time to Timestamp

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Converting Hundred Year Date Plus Time to Timestamp

Post by bbunney »

I have a 5 digit field that contains a 100 year date (Number of days difference between the current date and 1899-12-31) and a 5 digit time field (HHMMSS) and I need to convert them to an *ISO timestamp. They are in a a very old file. How would I do that? Thanks.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by jonboy49 »

If it is a 5 digit time field it cannot contain an HHMMSS value unless there is also an AM/PM indicator. Can you clarify please.

The basic calc would be something like:

Code: Select all

**free

dcl-s  realDate  date;
dcl-s  numDate   int(10)  inz(1);   // 1 day past the base
dcl-s  numTime   int(10)  inz(1);  //  And first minute of that day
dcl-s  realTimestamp  timestamp;

dcl-c  BASEDATE D'1899-12-31';


realDate = BASEDATE + %Days(numDate);
dsply %Char(realDate);

realTimestamp = realDate + %Time(numTime);
dsply %char(realTimestamp);

*InLr = *On;
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by bbunney »

It does not contain HHMMSS. It's just a number. Here is what the 2 fields values are:

Code: Select all

100 YR TRANS DATE  TRANS. TIME
      42,109         170,931  
      42,109         171,058  
      42,142         111,027  
      42,254          31,357  
      42,254          35,251  
      42,254          40,432  
      42,254          40,915  
      42,444          75,103  
      42,444          80,958  
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by Scott Klement »

From the first post in the thread:
bbunney wrote: Mon Mar 25, 2024 5:23 pm ... and a 5 digit time field (HHMMSS) ...
From the most recent post:
bbunney wrote: Mon Mar 25, 2024 6:23 pm It does not contain HHMMSS. It's just a number.
. . .

Code: Select all

100 YR TRANS DATE  TRANS. TIME
      42,109         170,931  
      42,109         171,058  
      . . .
I'm very confused. You have told us both that it does and doesn't contain an HHMMSS value, and you've told us that it is 5 digits, but are showing 6 digit numbers in it.
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by bbunney »

The hundred year date field is 5 digits (42109) and the time field is 6 digits (170931).
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by jonboy49 »

Then the code I gave you should work. Just substitute your own variable names for the numDate and numTime.

IF - the number represents HHMMSS. If it doesn't then we need to know what it does contain!
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Converting Hundred Year Date Plus Time to Timestamp

Post by bbunney »

Agreed. Thank you so much jonboy.
Post Reply