To get this to work, you are going to need to create 2 new alpha fields.

â€¢ File Opened Time-Seconds

â€¢ File Closed Time-Seconds

When a case is opened, youâ€™ll need to run the following command to fill in the File Opened Time-Seconds alpha field. This should be in the same Maths field/Linked action where the PUT( TODAY , {File Opened Date.Date} ) is.

Code: Select all

```
PUT( TIME-SECONDS , {File Opened Time-Seconds.Text} )
```

The following code will provide you with the x day(s) x hr(s) x min(s) x sec(s).

Code: Select all

```
# CaseDurationDays
#
# Get the number of days case is opened
v-a = DAYS-FROM-TODAY( {File Opened Date.Date} )
IF {File Closed Date.Date} = "" OR {File Closed Date.Date} = ? THEN
v-b = DAYS-FROM-TODAY( TODAY )
ELSE
v-b = DAYS-FROM-TODAY( {File Closed Date.Date} )
END
#
v-c = v-b - v-a
# Convert minus figure to positive
IF v-c < 0 THEN
v-c = ( v-c ) * ( -1 )
END
#
# Get the time in Seconds
v-FOTS = {File Opened Time-Seconds.Text}
IF {File Closed Date.Date} = "" OR {File Closed Date.Date} = "?" THEN
v-FCTS = TIME-SECONDS
ELSE
v-FCTS = {File Closed Time-Seconds.Text}
END
#
v-TS1 = ( v-FCTS ) - ( v-FOTS )
#
# Calculate number of days in seconds
IF v-c >= 1 THEN
v-DaySec = ( 86400 )
v-Tdays = ( v-c ) * ( v-DaySec )
v-TS2 = ( v-TS1 ) + ( v-Tdays )
ELSE
v-TS2 = v-TS1
END
#
# Convert minus figure to positive
IF v-TS2 < 0 THEN
v-TS2 = ( v-TS2 ) * ( -1 )
END
#
#
# Calculate days
v-TSdays1 = ( v-TS2 ) / ( 60 )
v-TSdays2 = ( v-TSdays1 ) / ( 60 )
v-TSdays3 = ( v-TSdays2 ) / ( 24 )
v-TSdaysR = ROUND( v-TSdays3 , 0 , -1 )
# Calculate hrs
v-TShrs1 = ( v-TSdays3 ) - ( v-TSdaysR )
v-TShrs2 = ( v-TShrs1 ) * ( 24 )
v-TShrsR = ROUND( v-TShrs2 , 0 , -1 )
# Calculate mins
v-TSmins1 = ( v-TShrs2 ) - ( v-TShrsR )
v-TSmins2 = ( v-TSmins1 ) * ( 60 )
v-TSminsR = ROUND( v-TSmins2 , 0 , -1 )
# Calculate sec
v-TSsec1 = ( v-TSmins2 ) - ( v-TSminsR )
v-TSsec2 = ( v-TSsec1 ) * ( 60 )
v-TSsecR = ROUND( v-TSsec2 , 0 , -1 )
#
v-days = TEXT( v-TSdaysR ) + TEXT( " day(s) " )
v-hrs = TEXT( v-TShrsR ) + TEXT( " hr(s) " )
v-min = TEXT( v-TSminsR ) + TEXT( " min(s) " )
v-sec = TEXT( v-TSsecR ) + TEXT( " sec(s)" )
v-text = TEXT( v-days ) + TEXT( v-hrs ) + TEXT( v-min ) + TEXT( v-sec )
#
PUT( v-text , {Ticket Duration.Text} )
#
# MESSAGE( v-text )
# MESSAGE( "v-a =" , v-a , NEWLINE , "v-b =" , v-b , NEWLINE , "v-c =" , v-c , NEWLINE , "v-FOTS =" , v-FOTS , NEWLINE , "v-FCTS" , v-FCTS , NEWLINE , "v-TS1 =" , v-TS1 , NEWLINE , "v-TS2 =" , v-TS2 , NEWLINE , "v-daysec =" , v-daysec , NEWLINE , "v-Tdays =" , v-Tdays , NEWLINE , "v-TSdays1 =" , v-TSdays1 , NEWLINE , "v-TSdays2 =" , v-TSdays2 , NEWLINE , "v-TSdays3 =" , v-TSdays3 , NEWLINE , "v-TSdaysR =" , v-TSdaysR , NEWLINE , "v-TShrs1 =" , v-TShrs1 , NEWLINE , "v-TShrs2 =" , v-TShrs2 , NEWLINE , "v-TShrsR =" , v-TShrsR , NEWLINE , "v-TSmins1 =" , v-TSmins1 , NEWLINE , "v-TSmins2 =" , v-TSmins2 , NEWLINE , "v-TSminsR =" , v-TSminsR , NEWLINE , "v-TSsec1 =" , v-TSsec1 , NEWLINE , "v-TSsec2 =" , v-TSsec2 , NEWLINE , "v-TSsecR =" , v-TSsecR , NEWLINE , NEWLINE , "v-text =" , v-text )
```

# Get the number of days case is opened

Code: Select all

```
# Get the number of days case is opened
v-a = DAYS-FROM-TODAY( {File Opened Date.Date} )
IF {File Closed Date.Date} = "" OR {File Closed Date.Date} = ? THEN
v-b = DAYS-FROM-TODAY( TODAY )
ELSE
v-b = DAYS-FROM-TODAY( {File Closed Date.Date} )
END
#
v-c = v-b - v-a
# Convert minus figure to positive
IF v-c < 0 THEN
v-c = ( v-c ) * ( -1 )
END
```

# Get the time in Seconds

Code: Select all

```
# Get the time in Seconds
v-FOTS = {File Opened Time-Seconds.Text}
IF {File Closed Date.Date} = "" OR {File Closed Date.Date} = "?" THEN
v-FCTS = TIME-SECONDS
ELSE
v-FCTS = {File Closed Time-Seconds.Text}
END
#
v-TS1 = ( v-FCTS ) - ( v-FOTS )
```

Take note, where the case isnâ€™t closed yet, then we use the system time as an alternative (similar to the PI Case Duration where days are calculated).

# Calculate number of days in seconds

Code: Select all

```
# Calculate number of days in seconds
IF v-c >= 1 THEN
v-DaySec = ( 86400 )
v-Tdays = ( v-c ) * ( v-DaySec )
v-TS2 = ( v-TS1 ) + ( v-Tdays )
ELSE
v-TS2 = v-TS1
END
#
# Convert minus figure to positive
IF v-TS2 < 0 THEN
v-TS2 = ( v-TS2 ) * ( -1 )
END
```

The v-DaySec bit that you see is calculated by:

60 = 60 (60 seconds in 1 minute)

60 x 60 = 3600 (3600 seconds in an hour)

3600 x 24 = 86400 (86400 seconds in 24 hours, or 1 day)

Iâ€™ve just placed this directly into a variable in Proclaim and skipped the calculation above. As 86400 will always be constant to equal 1 full day in seconds, we only need to use this to calculate the total number of days in seconds using the v-c variable we obtained earlier.

# Calculate days

Code: Select all

```
# Calculate days
v-TSdays1 = ( v-TS2 ) / ( 60 )
v-TSdays2 = ( v-TSdays1 ) / ( 60 )
v-TSdays3 = ( v-TSdays2 ) / ( 24 )
v-TSdaysR = ROUND( v-TSdays3 , 0 , -1 )
```

You divide the total number of seconds over the period by 60 to get minutes. Then 60 again to get the hours, then divide by 24 to get the days.

To provide a solid number, we then round the result down.

# Calculate hrs

Code: Select all

```
# Calculate hrs
v-TShrs1 = ( v-TSdays3 ) - ( v-TSdaysR )
v-TShrs2 = ( v-TShrs1 ) * ( 24 )
v-TShrsR = ROUND( v-TShrs2 , 0 , -1 )
```

Take note, that we arenâ€™t dividing our time any more, we are taking the remaining seconds from the previous calculation and then we are multiplying by 24 to get the hours.

Again, we round the result down to a solid number.

# Calculate mins

Code: Select all

```
# Calculate mins
v-TSmins1 = ( v-TShrs2 ) - ( v-TShrsR )
v-TSmins2 = ( v-TSmins1 ) * ( 60 )
v-TSminsR = ROUND( v-TSmins2 , 0 , -1 )
```

We also round the figure down for another solid number.

# Calculate sec

Code: Select all

```
# Calculate sec
v-TSsec1 = ( v-TSmins2 ) - ( v-TSminsR )
v-TSsec2 = ( v-TSsec1 ) * ( 60 )
v-TSsecR = ROUND( v-TSsec2 , 0 , -1 )
```

# Piecing the final result together

Code: Select all

```
# Piecing the final result together
v-days = TEXT( v-TSdaysR ) + TEXT( " day(s) " )
v-hrs = TEXT( v-TShrsR ) + TEXT( " hr(s) " )
v-min = TEXT( v-TSminsR ) + TEXT( " min(s) " )
v-sec = TEXT( v-TSsecR ) + TEXT( " sec(s)" )
v-text = TEXT( v-days ) + TEXT( v-hrs ) + TEXT( v-min ) + TEXT( v-sec )
```

I place the end result into an alpha field. Iâ€™ve done this just in case I need to report on this field later on. Using maths fields in reports can make reports run a little longer. If you wanted to, you could just use result = v-text if you werenâ€™t fussed about using a maths field directly on your screen.

Code: Select all

```
# MESSAGE( "v-a =" , v-a , NEWLINE , "v-b =" , v-b , NEWLINE , "v-c =" , v-c , NEWLINE , "v-FOTS =" , v-FOTS , NEWLINE , "v-FCTS" , v-FCTS , NEWLINE , "v-TS1 =" , v-TS1 , NEWLINE , "v-TS2 =" , v-TS2 , NEWLINE , "v-daysec =" , v-daysec , NEWLINE , "v-Tdays =" , v-Tdays , NEWLINE , "v-TSdays1 =" , v-TSdays1 , NEWLINE , "v-TSdays2 =" , v-TSdays2 , NEWLINE , "v-TSdays3 =" , v-TSdays3 , NEWLINE , "v-TSdaysR =" , v-TSdaysR , NEWLINE , "v-TShrs1 =" , v-TShrs1 , NEWLINE , "v-TShrs2 =" , v-TShrs2 , NEWLINE , "v-TShrsR =" , v-TShrsR , NEWLINE , "v-TSmins1 =" , v-TSmins1 , NEWLINE , "v-TSmins2 =" , v-TSmins2 , NEWLINE , "v-TSminsR =" , v-TSminsR , NEWLINE , "v-TSsec1 =" , v-TSsec1 , NEWLINE , "v-TSsec2 =" , v-TSsec2 , NEWLINE , "v-TSsecR =" , v-TSsecR , NEWLINE , NEWLINE , "v-text =" , v-text )
```

I also used this site http://www.timeanddate.com/date/timeduration.html to calculate the date and time to see if Proclaim has done it correctly. The site also does a brief breakdown to help check your figures.

SteveH