Calculate time elapsed for job completion

Post Reply
PdFUser5000
Member
Posts: 36
Joined: Fri Jun 12, 2020 11:23 am

Calculate time elapsed for job completion

Post by PdFUser5000 » Mon Oct 26, 2020 9:49 am

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.

laurentd
Member
Posts: 25
Joined: Wed Mar 13, 2019 2:06 pm

Re: Calculate time elapsed for job completion

Post by laurentd » Mon Oct 26, 2020 11:43 am

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"]"]
Solution Architect @ Enfocus

PdFUser5000
Member
Posts: 36
Joined: Fri Jun 12, 2020 11:23 am

Re: Calculate time elapsed for job completion

Post by PdFUser5000 » Mon Oct 26, 2020 12:53 pm

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)"]

laurentd
Member
Posts: 25
Joined: Wed Mar 13, 2019 2:06 pm

Re: Calculate time elapsed for job completion

Post by laurentd » Tue Oct 27, 2020 3:11 pm

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
Solution Architect @ Enfocus

Post Reply