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.

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
nightTrevors
  • 639
  • 4
  • 11
  • 24

1 Answers1

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.

Manish Patel
  • 4,411
  • 4
  • 25
  • 48
  • 6
    Awesome! thank you. For completeness, unix timestamp in kdb is q)floor((`long$.z.p)-`long$1970.01.01D00:00)%1e9 – nightTrevors Jul 13 '14 at 12:52
  • @nightTrevors Note that there should be a backtick prior to the word `long`. This backtick is hidden due to the comment format. – Contango Dec 19 '22 at 15:14