How to use .year inside function in KDB?

mchen

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?

jgleeson

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I use the k() function to receive data in kdb/q

From Dev

How to get first day of year in KDB/Q?

From Dev

How to use a function inside a custom jQuery function

From Dev

How to use a function inside a custom jQuery function

From Dev

How to use callback function inside a function?

From Dev

how to use unix date function to calculate quarter of the year

From Dev

how to use unix date function to calculate quarter of the year

From Java

Reactjs how to use ref inside map function?

From Dev

How to use data.table inside a function?

From Dev

dplyr: How to use group_by inside a function?

From Dev

How to use 'yield' inside async function?

From Dev

How to use the trim function to trim inside of a list

From Dev

How to use select query inside max function?

From Dev

How to use the trim function to trim inside of a list

From Dev

How can I use ddply inside a function?

From Dev

How to use data.table inside a function?

From Dev

How to use variable correctly inside this function?

From Dev

optparse main function, how to use the options inside

From Dev

How to use private struct inside of friend function?

From Dev

How to use require inside global and local function

From Dev

How to use INT() function inside an IF() statement Excel

From Dev

how to use a global variable inside a function in javascript?

From Dev

How to use $(this) inside JS function and then find attr?

From Dev

How to use max function inside IN clause

From Dev

How to use pattern matching inside a function?

From Dev

How to use top statement inside the sql function

From Dev

How to use requestAnimationFrame inside function with arguments?

From Dev

How to use a function's argument as an object of another object inside of the function?

From Dev

How to correctly use as.POSIXct function inside a cat function

Related Related

  1. 1

    How do I use the k() function to receive data in kdb/q

  2. 2

    How to get first day of year in KDB/Q?

  3. 3

    How to use a function inside a custom jQuery function

  4. 4

    How to use a function inside a custom jQuery function

  5. 5

    How to use callback function inside a function?

  6. 6

    how to use unix date function to calculate quarter of the year

  7. 7

    how to use unix date function to calculate quarter of the year

  8. 8

    Reactjs how to use ref inside map function?

  9. 9

    How to use data.table inside a function?

  10. 10

    dplyr: How to use group_by inside a function?

  11. 11

    How to use 'yield' inside async function?

  12. 12

    How to use the trim function to trim inside of a list

  13. 13

    How to use select query inside max function?

  14. 14

    How to use the trim function to trim inside of a list

  15. 15

    How can I use ddply inside a function?

  16. 16

    How to use data.table inside a function?

  17. 17

    How to use variable correctly inside this function?

  18. 18

    optparse main function, how to use the options inside

  19. 19

    How to use private struct inside of friend function?

  20. 20

    How to use require inside global and local function

  21. 21

    How to use INT() function inside an IF() statement Excel

  22. 22

    how to use a global variable inside a function in javascript?

  23. 23

    How to use $(this) inside JS function and then find attr?

  24. 24

    How to use max function inside IN clause

  25. 25

    How to use pattern matching inside a function?

  26. 26

    How to use top statement inside the sql function

  27. 27

    How to use requestAnimationFrame inside function with arguments?

  28. 28

    How to use a function's argument as an object of another object inside of the function?

  29. 29

    How to correctly use as.POSIXct function inside a cat function

HotTag

Archive