5

I would like to use dot notation to extract the year of a date.

q) myDate:2014.01.01;
q) myDate.year
2014i           / works OK

But when inside a function,

f:{[x] :x.year};
f[myDate]

I get an error (I use Studio for KDB+)

An error occurred during execution of the query.
The server sent the response:
x.year

What's going wrong?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
mchen
  • 9,808
  • 17
  • 72
  • 125

1 Answers1

5

As per this page on code.kx, this behavior is a quirk of q. To get around this, you can use the cast function.

q)f:{[x] :`year$x}
q)f[myDate]
2014i
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
jgleeson
  • 955
  • 5
  • 11