Find timestamp difference in day in kdb

kdb q-lang

932 观看


1625 作者的声誉

How do you find the time difference in days between 2 timestamp in KDB?

For eg.


how to find difference between these two timestamp in days?

q)d1-d2 //in day
作者: HadeS 的来源 发布者: 2017 年 12 月 27 日

回应 (2)


131 作者的声誉


You can cast to the date datatype and subtract:


or -

作者: wpc135 发布者: 27.12.2017 06:19


3569 作者的声誉

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:


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:

作者: Thomas Smyth 发布者: 28.12.2017 11:02