How do you find the time difference in days between 2 timestamp in KDB?
For eg.
q)d1:2019.02.16D12:16:00.000
q)d2:.z.P
how to find difference between these two timestamp in days?
q)d1-d2 //in day
How do you find the time difference in days between 2 timestamp in KDB?
For eg.
q)d1:2019.02.16D12:16:00.000
q)d2:.z.P
how to find difference between these two timestamp in days?
q)d1-d2 //in day
You can cast to the date datatype and subtract:
(`date$d1)-`date$d2
or
d1.date - d2.date
Depending on the accuracy you require you could simply do (`date$d1)-`date$d2
to check the difference of dates in days. If you are concerned with exact periods of 24 hours then the logic must be extended to include the time elements of the timestamp:
((`date$d1)-`date$d2)-0>(`time$d1)-`time$d2
Which checks to see if 24 hours have passed on the last day.
Alternatively you can compare the number of 24 hour increments in each timestamp by dividing by 1D00:00
and using floor
; as in the following function:
{floor(x-y)%1D00:00}[d1;d2]