Convert "Time(s) of Day" To Comparable Value(s), Either Numeric or Other Methods Welcome

Hi,

New to KM in the last couple weeks, and getting better and better. However, there is one issue that I seem unable to solve on my own.

I am using OCR to grab text on the screen, specifically, a Time of the day, such as "9:50 PM" and save it to a variable. I would like to then compare that variable saved time to the Current Time (%ShortTime%) to see if it is < or > X hours ago.

Specific Sequential Example:

  1. Get "9:50 PM" text from the screen and save to variable GrabbedTime
  2. If GrabbedTime < CurrentTime-6hours, then do certain things
  3. If GrabbedTime > CurrentTime-6hours, then do other certain things

Logically, if the three variables (GrabbedTime, CurrentTime, 6hours) were each converted into a Numeric value, then this would be easy math comparison.

Or if there is some other straightforward path here, any help is much appreciated.

tldr; trying to do actions based on how long ago the grabbed time is, can't figure out how to do it

Thank you!

1 Like

Hi @paintedrain. If necessary, I can provide more specific help later, but for now I suggest you check out:

Anytime I have to do calculations based on time I prefer using the NOW() function. It returns the current time in unixtime which makes comparing it to other times in that format incredibly easy.

But if you want or need to use a standard time format, then there's a way to subtract six hours using the ICUDateTime token. For instance...:

%ICUDateTimeMinus%6%Hours%hh:mm%

...will subtract 6 hours from the current time and display it like 11:39 (since it's currently 17:39 local time that's what it returns for me).

Regarding the OCR bit... just out of curiosity, what are you trying to OCR to get the time? Is it a file? Or an application? If it's an application, there would quite likely be a way to use AppleScript to get the info which would be much more reliable than OCR.