# Convert \*timestmp to readable format

**URL:** <https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples, Natural-on-Windows-Unix\
**Created:** [August 3, 2010, 5:11pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264 "2010-08-03T17:11:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kal2](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kal2](https://techcommunity.softwareag.com/u/Kal2)\
**Post date:** [August 3, 2010, 5:11pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/1 "2010-08-03T17:11:46Z")

</div>

I need to convert one ADABAS field which has stored \*timestmp in it,  
I need to convert that to readable format(numeric). Can someone please help me on this.

Thanks  
Kal

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 3, 2010, 7:48pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/2 "2010-08-03T19:48:34Z")

</div>

USR1023N (in SYSEXT) will convert it for you.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 3, 2010, 7:51pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/3 "2010-08-03T19:51:11Z")

</div>

Hello Kal,

Natural’s documentation says: \*TIMESTMP is an “Machine-internal store clock value”.

So this value could be different on different types of hardware.

On my Natural@Solaris, this value seems to stand for millonth of seconds since 1970-01-01 (if you ignore the rightmost 3 half-bytes - which are always zero).

Matthias

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 3, 2010, 8:05pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/4 "2010-08-03T20:05:46Z")

</div>

> [@Ralph Zbrog](#):
>
> USR1023N (in SYSEXT) will convert it for you.

Good idea to search in SYSEXT. But it seems USR1023N is not available on Open Systems…

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 3, 2010, 8:59pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/5 "2010-08-03T20:59:03Z")

</div>

I have it in Nat6.3.7 under both Windows and Linux.

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [August 4, 2010, 1:46am UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/6 "2010-08-04T01:46:44Z")

</div>

By the way, I`d be very interested in knowing (perhaps, some SAG gurus might answer this) why *TIMESTMP display/manipulation is so hidden from those "mere mortals" (in our shop, for example, we (programmers) don't have access to SYSEXT at all since "it`s too dangerous" 🙂

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 4, 2010, 4:03am UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/7 "2010-08-04T04:03:04Z")

</div>

Well, I (only a self-described guru) must agree that certain user exits should/must be restricted from mere mortals - several immediately come to mind: terminating user CICS sessions, manipulating UDB or TF parameters. A simple solution is for your Natural Administrator to copy specific modules from SYSEXT to SYSTEM or a Steplib. It should be a simple matter to make your case for access to USR1023N, especially since it can do no harm.

I recommend a download of the Community Edition of Natural to your personal PC (at home) so that you can play with SYSEXT. As a Natural developer, you should know what facilities are available. Then you can speak intelligently when you request access to additional user exits that will make your life easier.

---

<div class="post-metadata">

**Author:** ![Kal2](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kal2](https://techcommunity.softwareag.com/u/Kal2)\
**Post date:** [August 4, 2010, 11:53am UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/8 "2010-08-04T11:53:53Z")

</div>

Thanks everyone. But our administrator is not ready to copy USR1023N. We tried it already.Is there any way other than using USR1023N.

Thanks  
Kal

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 4, 2010, 5:53pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/9 "2010-08-04T17:53:18Z")

</div>

> [@Ralph Zbrog](#):
>
> I have it in Nat6.3.7 under both Windows and Linux.

Ok, we’re still on Nat 6.1.1 … :oops:  
But we will do an upgrade in September.

---

<div class="post-metadata">

**Author:** ![Ats](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Ats](https://techcommunity.softwareag.com/u/Ats)\
**Post date:** [August 4, 2010, 5:58pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/10 "2010-08-04T17:58:40Z")

</div>

I believe there is no harm in copying cataloged version of USR1023N (Not sure if SAG provides source as well :lol: )

Discuss with your Admin about it’s restriction. Here is the code that invokes the routine:

```auto
DEFINE DATA
LOCAL
1 #FUNCTION (A01)
1 #RET-CODE (N04)
1 #VALUES
  2 #TIME (T)
  2 #DATE (D)
  2 #TIMESTMP (B08)
  2 #MICRO-SEC (P19)
1 #MSG (A64)
END-DEFINE
SET KEY ALL
/*
MOVE *TIMX TO #TIME
MOVE *DATX TO #DATE
MOVE 'T' TO #FUNCTION
/*
REPEAT
  / ******************************************************
  INPUT WITH TEXT #MSG
    / ' ***Convert Time Variables***' (I)
    // 'Function .........' #FUNCTION (AD=MIT'_')
    / '(T) .............T' #TIME (AD=MI)
    / '(D) .............D' #DATE (AD=MI DF=L)
    / '*TIMESTMP .......S' #TIMESTMP (AD=MI)
    / 'Micro seconds ...M' #MICRO-SEC (AD=MIL)
  / ******************************************************
  IF *PF-KEY NE 'ENTR'
    STOP
  END-IF
  /*
  RESET #MSG
  /*
  CALLNAT 'USR1023N' #FUNCTION #RET-CODE #VALUES
  /*
  DECIDE ON FIRST #RET-CODE
    / '(T) .............T' #TIME (AD=MI)
    / '(D) .............D' #DATE (AD=MI DF=L)
    / '*TIMESTMP .......S' #TIMESTMP (AD=MI)
    / 'Micro seconds ...M' #MICRO-SEC (AD=MIL)
  / ******************************************************
  IF *PF-KEY NE 'ENTR'
    STOP
  END-IF
  /*
  RESET #MSG
  /*
  CALLNAT 'USR1023N' #FUNCTION #RET-CODE #VALUES
  /*
  DECIDE ON FIRST #RET-CODE
    VALUE 0 IGNORE
    NONE COMPRESS 'Error:' #RET-CODE TO #MSG
  END-DECIDE
  /*
END-REPEAT
END
```

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [August 4, 2010, 6:58pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/11 "2010-08-04T18:58:20Z")

</div>

Thank you very much, guys.

I can`t disagree less with " I believe there is no harm in copying cataloged version of USR1023N". Moreover, I`d go even further: I personally convinced there is no harm in making this user-exit (why is it a user-exit, for God`s sake?!) available as a standard NATURAL feature. As for those (like our NATURAL sysadmins who will "assess a possibility to give that user-exit to us") I`d say “May God judge them” 🙂

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 4, 2010, 7:25pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/12 "2010-08-04T19:25:53Z")

</div>

> [@Kal](#):
>
> Is there any way other than using USR1023N.

The other way would be to do it all by yourself:

```auto
define data local
01 #t (T) init <D'1900-01-01'> /* or whatever your epoch is
01 #b8 (B8)
01 redefine #b8
  02 #b2 (B2/4)
01 #p20 (P20)
01 #f8 (f8)
end-define
*
#b8 := *TIMESTMP
*
* interpret TIMESTMP as an unsigned integer
*
#p20:= #b2(1) /* since natural only treats B2 or B1 as unsigned int.
#f8 := #p20* 65536 * 65536 * 65536
#p20:= #b2(2)
#f8 := #f8 + #p20 * 65536 * 65536
#p20:= #b2(3)
#f8 := #f8 + #p20 * 65536
#p20:= #b2(4)
#f8 := #f8 + #p20
*
* ignore the rightmost 12 bit, and millionth --> tenth
*
compute rounded #p20= #f8 / 256 / 16 / 100000
*
* add tenths of seconds to epoch
*
#t := #t + #p20
*
display #t(EM=YYYY-MM-DD^HH:II) #b8 #f8 #p20 
end
```

---

<div class="post-metadata">

**Author:** ![Wayne\_Campos](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wayne_campos/32/104_2.png) [@Wayne\_Campos](https://techcommunity.softwareag.com/u/Wayne_Campos)\
**Post date:** [August 5, 2010, 9:40pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/13 "2010-08-05T21:40:31Z")

</div>

Hello everyone,  
Kal is being less than truthful with you. I happen to know that Kal has not asked his admin about copying USR1023N. Also, I know that USR1023N is already in the SYSTEM library on Kal’s system. I am not even sure why Kal is asking questions about NATURAL since he is supposed to be processing this field with a COBOL program. In fact, I am not sure that Kal is authorized to even attempt to log on to NATURAL.

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [August 6, 2010, 1:26am UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/14 "2010-08-06T01:26:50Z")

</div>

Hi everybody,

Perhaps, it will be too much for such a small subject, but I personally liked MUCH BETTER “other way to do it” from Matthias than that Wayne`s “clarification”.  
As for myself, I still have no access to that USER EXIT (would NOT pretend that I need it right now)  
Just my 2 cents

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 6, 2010, 6:03pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/15 "2010-08-06T18:03:58Z")

</div>

By the way:

\*TIMESTMP seems to be timezone-independent… i.e. GMT.

\*TIMX is local time.

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [August 6, 2010, 8:32pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/16 "2010-08-06T20:32:39Z")

</div>

I agree that generally more people will find the information helpful on how to parse timestamps besides the USR routine, but I also empathise with the need to defend one’s self against libel.

I am sure the very helpful Matthias would post a retort if someone else posted that he ate babies for breakfast (I am sure he does not eat babies for breakfast - that was a rhetorical example).

Enough said on that.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:58pm UTC](https://techcommunity.softwareag.com/t/convert-timestmp-to-readable-format/94264/17 "2021-04-02T14:58:50Z")

</div>


