Search code examples
kdb+

For -12h timestamp, why does the "ts.date" syntax not work within a function?


I am trying to get the 30-second multiple of a timestamp:

q)ts:2025.02.14D11:09:31.033
q)ts.date  + 30 xbar `second$ts
2025.02.14D11:09:30.000000000

When I do this in a function it behaves differently:

q)f:{[t]: t.date  + 30 xbar `second$t}
q)f ts
2000.01.02D11:09:30.000000000

Notice how the date has been lost here and turned into 2000.01.02

Can someone explain what is happening here?


Solution

  • This is because

    Unfortunately, at the time of this writing (Sep 2015) dot notation for extraction (still) does not work inside functions.

    https://code.kx.com/q4m3/2_Basic_Data_Types_Atoms/#257-constituents-and-dot-notation

    just refactor your code and this should work

    f:{[t]: $[`date;ts]  + 30 xbar `second$t}
    f ts
    2025.02.14D11:09:30.000000000