Search code examples
kdb+q-langisodate

How to produce a formatted date string in Q/KDB?


How can one produce an ISO date string "yyyy-MM-dd" from a Q date type? I looked at concatenating the various parts but am not even able to get the day/month, e.g. d:2015.12.01;d.month prints 2015.12, i.e. more than just the month.


Solution

  • q)"-" sv "." vs string[2015.12.01]
    "2015-12-01"
    

    vs vector from string, splits by "." above; sv string to vector, join by "-" above.

    Remember a string is just a char array, so you can grab each part as you require with indexing. But the above is useful as the resulting vector of vs gives a 3-length vector that you manipulate any way you like