Question
· Aug 11, 2017

How to get from caché server actual linux TIMESTAMP(in seconds)?

Good day,

I need to find out if it is possible somehow to receive actual linux TIMESTAMP for example with $NOW() or other functions.
I was trying to recalculate it with $NOW() function, but without success. I would like to simulate Redis TIME command in COS.


My tryings:

USER > set time = $NOW()

USER > w (($PIECE(time,",",1)*86399) + $PIECE(time,",",2))
5573319043.403186

But in Redis it is:

> time
​1) 1502471158

On web page: http://try.redis.io/
type "time" + enter. And it will results as short documentation says: https://redis.io/commands/time

And this behavior I would like to implement in COS.

Additional sub-question for this question is:
How to receive number of elapsed microseconds from caché server actual linux TIMESTAMP from actual second? Is it possible?

Thanks in advance for your thoughts/answers.

Discussion (7)0
Log in or sign up to continue

When processing the two pieces of a timestamp such as $ZTS it is safer to assign the timestamp once to a variable, then operate on that variable, e.g.  instead of

W (+$ZTS-47117*86400) + $J($P($ZTS,",",2),0,0)

use

S zts=$ZTS W (+zts-47117*86400) + $J($P(zts,",",2),0,0)

This avoids the edge case in the original code, where the first evaluation of $ZTS happens just before the midnight rollover and the second evaluation at or just after it.

As to your second part, $ZTS is the most precise time you have.
On unix:

The $ZTIMESTAMP time value is a decimal numeric value that counts the time in seconds and fractions thereof. The number of digits in the fractional seconds may vary from zero to nine, depending on the precision of your computer’s time-of-day clock. On Windows systems the fractional precision is three decimal digits; on UNIX® systems it is six decimal digits. $ZTIMESTAMP suppresses trailing zeroes or a trailing decimal point in this fractional portion.

(http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...)