Home > OS >  compare just time part from datetime in kql
compare just time part from datetime in kql

Time:01-24

I want to compare just the time part of different datetimes.

the result gives me false, but it should be true. what am I missing here? is there a better way to do it.

this is what I tried, and the logic seems to fail:

let current_future = format_datetime(now( 2h), 'HH:m:s.fff');
//print current_future
let current_past = format_datetime(now(-1h), 'HH:m:s.fff');
//print current_past
let result = iff((todatetime(current_past) < todatetime(current_future)), "true", "false");
print result ```

CodePudding user response:

To extract the time from a datetime value, you should do % 1d.

let x = datetime(2022-01-23 09:55:16);
let y = datetime(2022-01-21 19:55:16);
print x<y, (x) < (y)

Result:

print_0 print_1
False True

CodePudding user response:

You could use timespan.

let t1 = datetime(2022-01-01 23:44:55);
let t2 = datetime(2022-02-01 08:22:33);
print (t1 - bin(t1,1d)) < (t2 - bin(t2,1d)) 

Your solution is problematic since you are not using 2 digits hour and alphabetically '8' (like in 8:22:33) is bigger than '23' (like in 23:44:55)

  •  Tags:  
  • Related