Logic used to convert from time stamp hexadecimal value

Hi All,

We have requirement to read a record from adabas. There is a time stamp field which is holding a hexadecimal value. On the screen it is showing following time stamp (human readable format) where as in the database it is storing hex format. Please find the example below.

Can you please tell me what logic or algorithm natural follows to convert into hex format. Because whatever logic I tried, I am not getting the given hex value.

Here is the time stamp on the screen:
12-11-2020 14:13:22.4 (format: MM-DD-YYYY HH:MI:SS.T). Here T stands for one 10th of a sec.

Based on your response I will decode the hex value and send it to the downstream system.

Thank you very much for your help.

If this is on the mainframe, it is most likely based on a *TIMESTMP value - the machine internal clock value (an IBM z/OS value). Natural library SYSEXT provides a utility API to convert the value from its internal timestamp value to a human-readable date-time clock value.

Hi Douglas,

Thanks for response !

I am looking for the logic how mainframe is converting from timestamp to hexa decimal value. because I need to implement the similar logic on my middleware application.

for example, does it convert time stamp into milliseconds (since 1st January 1970) and then converts into hexa decimal value. I have tried it but I am getting a different hexadecimal value.

I am getting: 5fd37e82

So, I am wondering how mainframes is generating (I mean what logic is used) this hexa decimal value: D8CF9CC78CA37BC7

Thanks,
Bala

Try Googling STCK conversions, such as How do I format a STCK from a C program? – ColinPaice

The API USR1023N in library SYSEXT is used for time conversions. The text member USR1023T contains the description. It gives you also an overview of the copycodes.
There are also copycodes delivered. You can take a look into the copycodes to see how time conversion works.

USR1023Y - Convert a store clock value into microseconds.
/* Transferred Parameters
/* ----------------------
/* &1& Input: store clock value, format (B8), such as TIMESTMP
/
&2& Output: microseconds since 1900-01-01 00:00:00,
/* format (P19), (N19) or (F8)

USR1023X - Convert microseconds into Natural time.
/* Transferred Parameters
/* ----------------------
/* &1& Input: microseconds since 1900-01-01 00:00:00,
/* format (P19), (N19) or (F8)
/* &2& Output: Packed field (P12), redefinition of Natural time
/* value (T)

The conversion is straight forward. The conversion from Natural format into human readable format is done in Natural inside.

/* Store Clock Value:
/* The Natural system variable TIMESTMP provides the machine-internal
/
store clock value as (B8) binary value.
/* The layout of the store clock value is described in
/* IBM z/Architecture Principles of Operation
/* > Chapter 4. Control > Timing
/*
/* Summary of store clock value:
/* - The clock controls a 64 bit register.
/* - Leftmost bit is at position 0; it is the MSB (most signif. bit).
/* - Bit position 31 is incremented every 1.048576 seconds.
/* - Bit position 51 represents exactly one microsecond.
/* - Bit position 59 (if implemented), represents 3,90625 nano
/* seconds.
/* - Bit position 63 (if implemented), is approximately 244 pico
/* seconds.
/* - On MF bit position 60-63 contains the processor ID
/* (max. 16 processors)
/* - On Windows and UNIX the accuracy is at least microseconds.
/* For uniqueness, if two timestamps are within a one time unit,
/* an offset will be added by Natural.
/* - One day adds 0001 41DD 7600 0000 to the clock.
/* - The clock starts on:
/* 1900-01-01 00:00:00.000000 (GMT)
/* with store clock = 0000 0000 0000 0000
/* - The clock ends at 2042-09-17 23:53:47.370495 (GMT)
/* with store clock = FFFF FFFF FFFF F000
/* - Clock settings at start of year:
/* 1976 … 8853 BAF0 B400 0000
/* 1984 … 96AD 84B5 9000 0000
/* 1992 … A507 4E7A 6C00 0000
/* 2000 … B361 183F 4800 0000
/* 2042 … FEB9 1C77 8600 0000
/* - The store clock range corresponds to the following range
/* of microseconds (since 1900-01-01 00:00:00.000000):
/* 0 <= microseconds <= 4503599627370495
/*
/* Natural Time Value
/* The Natural system variable TIMX provides the time of day
/
in internal Natural time format (T) represented by a 12 byte packed
/* field (P12).
/*
/* Summary of Natural time value:
/* - The packed value is incremented every 1/10 second.
/* - The Natural time starts on:
/* 0000-01-02 00:00:00.0
/* with packed value = 0
/* - The Natural time ends at 3168-11-16 09:46:39.9
/* with packed value = 999999999999
/* - The Natural time range corresponds to the following range
/* of microseconds (since 1900-01-01 00:00:00.000000):
/* -59958144000099999 <= microseconds <= 40041855999999999