Search code examples
datekdb

Create date from day, month, year as integers in KDB Q


I am trying to get a date from its integer components: I have day, month and year as variables (that can change, I don't want to hard code them), and I want to reunite them in a date variable.

For example, something like that;

myDay: 15

myMonth: 4

myYear: 2016

`date$(myYear,myMonth,myDay) --> should return 2016.4.15 (formatted as a date).

Any way to do that? Thank you


Solution

  • q)d:3
    q)m:8
    q)y:2016
    q)"D"$"." sv string (y;m;d)
        2016.08.03
    

    See cast vs tok - need to use different arguments depending on if what you're casting from is a string or not