Search code examples
kdb

How to work with date and time in KDB


I tried to work with dateDtimespan type by subtracting one dateDtimespan from another, but KDB (QPad) always shows 0 as a result, why?

Also if I have, say, datetime 12.11.2014:22:33:00.000000000 in one column and only time 22:32:00.000000000 in another, how I may remove date part from the first column to subtract time portion from the second column?


Solution

  • to remove the date, you can use the cast operator, $. To reference only the time, you can prefix $ with `time as shown below.

    q).z.z
    2015.02.23T14:10:33.523
    
    q)`time$.z.z
    14:10:30.731
    
    q)t:([]ts:10#.z.N;ti:.z.t-til 10)
    
    q)exec `time$ts-ti from t
    
    00:00:00.000 00:00:00.001 00:00:00.002 00:00:00.003 00:00:00.004 00:00:00.005..
    

    You can see more examples here. http://code.kx.com/q/ref/casting/#cast