5

Is there a built-in way of getting the Unix timestamp in kdb/q?

Something like

`float$.z.p

would be ideal; otherwise I'll have to resort to a more laborious implementation where I count the seconds from Jan 1 1970.

1 Answer 1

5
q)`long$.z.p
458558447196132000
q)`long$1970.01.01D00:00
-946684800000000000

So you can get nanos from 2000.01.01. From there it's a simple calculation to convert to and from a 2000.01.01-based epoch vs 1970.01.01 based epoch.

Sign up to request clarification or add additional context in comments.

2 Comments

Awesome! thank you. For completeness, unix timestamp in kdb is q)floor((long$.z.p)-long$1970.01.01D00:00)%1e9
@nightTrevors Note that there should be a backtick prior to the word long. This backtick is hidden due to the comment format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.