Re: How to calculate part of duration (452 Views)
Trusted Contributor
Posts: 990
Registered: ‎10-06-2009
Message 1 of 9 (488 Views)

# 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 ?

Honored Contributor
Posts: 4,414
Registered: ‎06-17-2010
Message 2 of 9 (477 Views)

# 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.
Trusted Contributor
Posts: 990
Registered: ‎10-06-2009
Message 3 of 9 (458 Views)

# Re: How to calculate part of duration

[ Edited ]

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 :)

Highlighted
Honored Contributor
Posts: 3,901
Registered: ‎07-13-2007
Message 4 of 9 (452 Views)

# Re: How to calculate part of duration

[ Edited ]

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
Trusted Contributor
Posts: 990
Registered: ‎10-06-2009
Message 5 of 9 (437 Views)

# Re: How to calculate part of duration

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

Honored Contributor
Posts: 3,901
Registered: ‎07-13-2007
Message 6 of 9 (434 Views)

# Re: How to calculate part of duration

[ Edited ]

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
Trusted Contributor
Posts: 990
Registered: ‎10-06-2009
Message 7 of 9 (431 Views)

# 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 ?
Honored Contributor
Posts: 3,901
Registered: ‎07-13-2007
Message 8 of 9 (424 Views)

# 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
Trusted Contributor
Posts: 990
Registered: ‎10-06-2009
Message 9 of 9 (421 Views)

# Re: How to calculate part of duration

ok.
I did use next line in trigger:
...
var TemplateBreach_50 = system.functions.val(((system.functions.val(TemplateBreach, 1))/2),3);
var TemplateBreach_75 = system.functions.val(((system.functions.val(TemplateBreach, 1))*3/4),3);
...
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.