starttime-endtime

Discuss RoboTask here
Post Reply
5243
Posts: 23
Joined: Wed Feb 25, 2015 12:04 pm

starttime-endtime

Post by 5243 »

Hi Oleg
I want to extract time, for example 13:01:57 – 14:01:30 = 3591 sec or 0:59:51
I have used your basic example “amount of seconds to time” (attached)
but there are some problems with it:
first of all, it will not display always two digits
example “ 12:01:03 = 12:1:3”
second if you have a time difference between one day the value become negatief
example “ 23:01:12 – 14:01:30 = -32382 sec or -8:59: -42
Is there al simple way to extract time? with a outcome in HH:MM:SS and sometimes a DAY?
Thanks
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: starttime-endtime

Post by Oleg »

Use VB evaluate.
See my example. This should work without problem if the difference less then 24 hours.

The function is very simple:

Code: Select all

function difference(Time1, Time2)
  d1 = CDate(Time1)
  d2 = CDate(Time2)
  d3 = cdate(d2-d1)
  difference = CStr(d3)
end Function
Usage example: difference("17:02:01", "17:05:23")

See below the full task:

Code: Select all

 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task209"
Hide=INTEGER|0
ID=INTEGER|1560806310
LogOnAsUser=INTEGER|1
Name=STRING|"Date-time difference"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""T1"" with value ""{datetime}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"T1"
varvalue=STRING|"{datetime}"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Wait some time."""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"Wait some time."
msg1=STRING|"Then, press OK "
msg3=STRING|"The task calulates the time"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""T2"" with value ""{datetime}"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"T2"
varvalue=STRING|"{datetime}"

[Actions\Action4]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate"
Params=FOLDER

[Actions\Action4\Params]
expression=STRING|"difference(""{t1}"",""{t2}"")"
line00000000=STRING|"function difference(Time1, Time2)"
line00000001=STRING|"  d1 = CDate(Time1)"
line00000002=STRING|"  d2 = CDate(Time2)"
line00000003=STRING|"  d3 = cdate(d2-d1)"
line00000004=STRING|"  difference = CStr(d3)"
line00000005=STRING|"end Function"
line00000007=STRING|"'LogMessage(difference(""17:02"", ""17:02:23""))"
linecount=STRING|"8"
loadfromfile=STRING|"1"
variable=STRING|"d"

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""You have waited: {d}"""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"You have waited: {d}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
5243
Posts: 23
Joined: Wed Feb 25, 2015 12:04 pm

Re: starttime-endtime

Post by 5243 »

Thank you!
Post Reply