Search code examples
kdb

How do I parse datetime in KDB Q?


I have minutely data:

t                    o      h      l      c      v    
------------------------------------------------------
2016-01-04T09:00:00Z 105.45 105.45 103.6  103.6  17462
2016-01-04T09:03:00Z 103.7  103.99 103.7  103.99 893  
2016-01-04T09:06:00Z 103.7  103.7  103.7  103.7  335  

Which I've read in with:

f: `:/home/chris/sync/us_equities/AAPL.csv
show flip `t`o`h`l`c`v!("SFFFFI";",")0: f

I'm trying to work out how to parse the ISO8601 timestamp into something KDB understands. How should I do it?

This is my first time using q.


Solution

  • You can drop the last character (-1_) from each value on the right (/:) and then parse ($) to timestamp

    f: `:/home/chris/sync/us_equities/AAPL.csv
    tab:flip `t`o`h`l`c`v!("*FFFFI";",")0: f
    update "P"$-1_/:t from tab
    

    Note that * should be used for generic text data rather than S