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.

Vote up!
Vote down!

Rating: 0

Comments: 4 Views: 79

3 answers

Answer

I wrote this function to get the Linux UTC time, which I'm pretty sure is what Redis time is showing. 

 

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

 

> time

1) 1502473916

 

Ahmed

Vote up!
Vote down!

Rating: 2

Yes ,true. This is more precise. Thanks

Vote up!
Vote down!

Rating: 0

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.

Vote up!
Vote down!

Rating: 2

Answer
w $ZDT($NOW(),-2)

Cheers,
Fab

Vote up!
Vote down!

Rating: 2

Thanks! It works.

Vote up!
Vote down!

Rating: 0

Answer

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=...)

Vote up!
Vote down!

Rating: 1

Hmm, I see. Yes, thanks for explanation.

Vote up!
Vote down!

Rating: 0

Log in to answer