Page 1 of 1

Calculate time elapsed for job completion

Posted: Mon Oct 26, 2020 9:49 am
by PdFUser5000
I am trying to calculate time elapsed for completing a job.I'm using Privatedata keys for this, but the answer comes out wrong. Is my formatting wrong?


JobStart=[Switch.Date:Format="hh-mm-ss",TimeZone="System"]

JobEnd=[Switch.Date:Format="hh-mm-ss",TimeZone="System"]

[Switch.Calculation:Expression="[Job.PrivateData:Key="JobEnd"]-[Job.PrivateData:Key="JobStart"]"]

09-36-29 - 09-34-05 gives an answer -104. The correct answer should be 144 (seconds).

I want this number to be shown in an email.

Re: Calculate time elapsed for job completion

Posted: Mon Oct 26, 2020 11:43 am
by laurentd
You are subtracting a time from a time.
You should subtract an amount of seconds from an amount of seconds.

This works:

JobStart=[Switch.Calculation:Expression="[Switch.Date:Format="MM",TimeZone="System"] * 31 * 24 * 3600 + [Switch.Date:Format="dd",TimeZone="System"] * 24 * 3600 + [Switch.Date:Format="hh",TimeZone="System"] * 3600 + [Switch.Date:Format="mm",TimeZone="System"] * 60 + [Switch.Date:Format="ss",TimeZone="System"]"]

JobEnd=[Switch.Calculation:Expression="[Switch.Date:Format="MM",TimeZone="System"] * 31 * 24 * 3600 + [Switch.Date:Format="dd",TimeZone="System"] * 24 * 3600 + [Switch.Date:Format="hh",TimeZone="System"] * 3600 + [Switch.Date:Format="mm",TimeZone="System"] * 60 + [Switch.Date:Format="ss",TimeZone="System"]"]

[Switch.Calculation:Expression="[Job.PrivateData:Key="JobEnd"] - [Job.PrivateData:Key="JobStart"]"]

Re: Calculate time elapsed for job completion

Posted: Mon Oct 26, 2020 12:53 pm
by PdFUser5000
Thank you very much!
//
Just a small extra question, if i want to convert this to minutes and seconds, i use something like this?

for minutes:
[Switch.Calculation:Expression="((([Job.PrivateData:Key="PDFEnd"] - [Job.PrivateData:Key="PDFStart"])- (([Job.PrivateData:Key="PDFEnd"] - [Job.PrivateData:Key="PDFStart"])%60))/60)"]

for seconds:
[Switch.Calculation:Expression="(([Job.PrivateData:Key="PDFEnd"] - [Job.PrivateData:Key="PDFStart"])%60)"]

Re: Calculate time elapsed for job completion

Posted: Tue Oct 27, 2020 3:11 pm
by laurentd
Add an extra folder where you define this private data (time in seconds):
JobTime=[Switch.Calculation:Expression="[Job.PrivateData:Key="JobEnd"] - [Job.PrivateData:Key="JobStart"]"]

Then to get the processing time in minutes and seconds, use this:

for minutes: [Switch.Calculation:Expression="( [Job.PrivateData:Key="JobTime"] - ( [Job.PrivateData:Key="JobTime"] % 60 ) ) / 60"] min
for seconds: [Switch.Calculation:Expression="[Job.PrivateData:Key="JobTime"] % 60"] sec