Subtraction of two strings

I want to subtract the WindowEnd time & WindowStart time . My windows registry values.

f1

Written as

((((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))) - (((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))))

I am getting error as " The operator “minus” is not defined" .

Can you assist me here.

How about something like this (based on the above):

((((last 4 of ("0000" & ((it / 60) as string & last 2 of ("00" & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value "WindowEnd" of it as string) of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry) as string))) as integer - (((last 4 of ("0000" & ((it / 60) as string & last 2 of ("00" & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value "WindowStart" of it as string) of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry) as string))) as integer)

Or depending on your use case, here’s a simplified version:

(value "WindowEnd" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as integer) - (value "WindowStart" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as integer)

Hi Aram ,

It suppose to give me result as 1 hour , 10 mins. But I am getting as 70 mins.

Q: ((((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))) as integer - (((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))) as integer)
A: 70
T: 384

Q:

=====

Q: (value “WindowEnd” of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maint
enance\Reboot” of native registry as integer) - (value “WindowStart” of key “HKE
Y_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry
as integer)
A: 70
T: 23332

Note :

As per Pic example : WindowEnd : 1030 ,

first 2 digit is hours and another 2 digit is mints.

Calculation example

WindowStart : 0850
WindowEnd : 0920

If we subtract: 30 mins , we suppose to get .

that’s what the logic we need .

Clock is 24 format

Is that possible to calculate ? waiting for your feedback.

See if this will help you

Q: 70 / 60
A: 1
T: 0.042 ms

Q: 70 mod 60
A: 10
T: 0.027 ms
1 Like

It won’t work this way. Example

my Start time : 0630
my end time : 0700

my actual duration is only 30 mins.

My start time : 2300
My end time : 2330

this also , 30 mins calculation . Here is the kick off . when we use / 60 , it will consider as 1 hr only

I have tried to subtract in the below mechanism. However I am getting error.

Q: ((two digit hour of it) of current time_of_day)
A: 04
T: 310

Q:


if ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer <= (first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer) then ((((two digit hour of it) of current time_of_day)) - (first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer + ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer)) else ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer) - ((first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer)

Error as

E: The operator “minus” is not defined.
T: 1554

Not sure , how I can fix this now .

Not working as expected.

You cannot perform “math” on strings. You must convert them to Integers.

Q: ((two digit hour of it) of current time_of_day) as Integer
A: 9
T: 0.063 ms

then you will need to convert it back to a string if you want to append it with text as in the original post.

Q: ((((two digit hour of it) of current time_of_day) as Integer / 3) as string) & " Hours"
A: 3 Hours
T: 0.059 ms
2 Likes

Thanks . Great . However I got it as follows .

Q: if ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHIN
E\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer <
= (first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\S
OFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer) the
n ((((two digit hour of it) of current time_of_day) as integer) - (first 2 of (v
alue “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\KaiserPe
rmanente\Maintenance\Reboot” of native registry) as integer + ((first 2 of (valu
e “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\KaiserPermane
nte\Maintenance\Reboot” of native registry) as integer)) else ((first 2 of (valu
e “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\KaiserPermane
nte\Maintenance\Reboot” of native registry) as integer) - ((first 2 of (value “W
indowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\KaiserPermanent
e\Maintenance\Reboot” of native registry) as integer)
A: 1
T: 724

Q:

Here my system time is 6:35am. Hence given 1 value is wrong one .

11

My code now as

if ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer <= (first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer) then ((((two digit hour of it) of current time_of_day) as integer) - (first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer + ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer)) else ((first 2 of (value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer) - ((first 2 of (value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as integer)

Given your relevance that returned a value of “70”, I’ve integrated it as follows …

Q: (((it /60) as string & " hour " & (if ((it/60) > 1) then ("s") else ("")) & (if ((it mod 60) > 0) THEN ((it mod 60) as string & " minute" & (if ((it mod 60) > 1) then ("s") else (""))) ELSE (""))) of ((((last 4 of ("0000" & ((it / 60) as string & last 2 of ("00" & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value "WindowEnd" of it as string) of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry) as string))) as integer - (((last 4 of ("0000" & ((it / 60) as string & last 2 of ("00" & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value "WindowStart" of it as string) of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry) as string))) as integer))
A: 1 hour 10 minutes
T: 0.099 ms

Testing now . Thanks .

Q:(((it /60) as string & " hour " & (if ((it/60) > 1) then (“s”) else (“”)) & (if ((it mod 60) > 0) THEN ((it mod 60) as string & " minute" & (if ((it mod 60) > 1) then (“s”) else (“”))) ELSE (“”))) of ((((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowEnd” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))) as integer - (((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer) of it) of ((value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))) as integer))
A: 1 hour 10 minutes
T: 1083

My registry value :

12

It’s giving wrong answer …

Let me take a look …

Are those times HHMM or are they like a Julian clock that simply counts up the number of minutes from a “start time”?

In other words, is that 6:40am and 7:10am?

yes . you are right . HHMM.

As per above pic ,

yes, 06:40am to 07:10am .

I don’t have those registry keys, so it’s harder to test your values, but try this …

Q: (((it /60) as string & " hour " & (if ((it/60) > 1) then ("s") else ("")) & (if ((it mod 60) > 0) THEN ((it mod 60) as string & " minute" & (if ((it mod 60) > 1) then ("s") else (""))) ELSE (""))) of ((((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowEnd" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry)) as integer - (((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowStart" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry)) as integer))

I am getting error as

E: The operator “substring” is not defined.

OK, I broke down and added the Registry keys. The reference to the keys has to be re-cast “AS STRING” for the Substring object to be available. Give these a try …

Q: (((it /60) as string & " hour " & (if ((it/60) > 1) then ("s") else ("")) & (if ((it mod 60) > 0) THEN ((it mod 60) as string & " minute" & (if ((it mod 60) > 1) then ("s") else (""))) ELSE (""))) of ((((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowEnd" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as string)) as integer - (((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowStart" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as string)) as integer))
A: 0 hour 30 minutes
T: 0.310 ms

or

Q: (((IF (it > 60) THEN ((it /60) as string & " hour " & (if ((it/60) > 1) then ("s") else (""))) ELSE ("")) & (if ((it mod 60) > 0) THEN ((it mod 60) as string & " minute" & (if ((it mod 60) > 1) then ("s") else (""))) ELSE (""))) of ((((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowEnd" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as string)) as integer - (((substring (0,2) of it) as Integer * 60 + ((substring (2,2) of it) as Integer)) of (value "WindowStart" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" of native registry as string)) as integer))
A: 30 minutes
T: 0.302 ms
1 Like

Wawww. Working now . Let me test with different times and make sure all works good .

Thanks a lot for your support.