Service Manager / Service Center Practitioners Forum
cancel

## How to calculate part of duration

SOLVED
Go to solution
Highlighted
Acclaimed Contributor.

## How to calculate part of duration

Hello.

I have a field (Data/Time) which contain duration time, how can i calculate in SL some parts of this duration: 1/2, 3/4 ?

8 REPLIES
Acclaimed Contributor.

## Re: How to calculate part of duration

Hi,

What do you mean by some part ?

you can use substr function to pull some sub string of this.

use like,
\$b=substr(date.field in\$file, 1, 7)

or if you need date or time then us function like day,date,dayof week,month

======
A RAD function that extracts a substring from a string.

Function
substr
Format
substr(string, beginning position, length)
Parameters
The following parameters are valid for the substr function: Parameter Data type Description
\$string String The string being modified.
beginning position Number The position in the string where the substring is to begin.
length Number The total number of characters you want the substring to contain. The default behavior is to include all remaining characters in the string from the starting position. You can use the length parameter to specify a shorter substr length.

Example
\$a=substr("Service Manager", 8)
\$b=substr("Service Manager", 1, 7)
After execution, the value of \$a is Center and the value of \$b is Service.

hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Acclaimed Contributor.

## Re: How to calculate part of duration

When i told about part i mean if field have value "08:00:00" and i whant to get 1/2 и 3/4 of this value - that 04:00:00 and 06:00:00. (multiplying and dividing the value of the field by a specified amount.)

part of value not part of string :)

Acclaimed Contributor.

## Re: How to calculate part of duration

It appears that you can perform a mathmatical operation directly against a duration. From the RAD Debugger:

x \$test='08:08:12'
08:08:12                 set variable to date/time duration
d \$test='08:08:12'
true                            verify successful initializtion of variable
d type(\$test)
3                                field type is date/time before the calculation
>d type(\$test/2)
3                                field type is still date/time after the calculation
d (\$test/2)
04:04:06                value is 1/2 original duration

If you want to be really careful, you could convert your duration to numeric, divide, then convert back to date/time:

\$placeholder=val(duration in \$file,1)      converts duration in record to numeric equivalent

\$placeholder=\$placeholder/2                   divides numeric equivalent by two

duration in \$file=val(\$placeholder,3)      converts result back to date/time and saves result to duration field in record

You could probably even nest it like crazy!

duration in \$file=val((val(duration in \$file,1)/2),3)

----------------------------------------------------
Kudos - what, where, how, and why
Acclaimed Contributor.

## Re: How to calculate part of duration

Yes. It's perfectly work in RAD debugger, but i need do it in trigger.

Acclaimed Contributor.

## Re: How to calculate part of duration

Use JavaScript in the trigger to call a process and execute the RAD in a process.

[EDIT: not sure what happened to the rest this post, but adding it now.]

You could also just do it with JavaScript from the trigger. The PriorityCalc JavaScript does something similar:

--It takes the urgency and impact (character fields), converts them to numbers, does some math to calculate priority, then changes the result back to a character field to save as priority.code.

You could use that as a model for what you want to do.

----------------------------------------------------
Kudos - what, where, how, and why
Acclaimed Contributor.

## Re: How to calculate part of duration

can i use in script same simple command to divide value in date field of table to get same result like in RAD debugger ?
Acclaimed Contributor.

## Re: How to calculate part of duration

YES. I suggested that but for some reason the post was incomplete.

----------------------------------------------------
Kudos - what, where, how, and why