Calculating Time from an Alpha Field - Using SPLIT & LENGTH

Solved a problem in an elegant manner and want to show off your code? Know a hard-to-find feature? Post it here for the benefit of others. Questions don't belong here.
Post Reply
DeborahMonks
Posts: 10
Joined: Thu Jan 02, 2014 3:00 pm
Has thanked: 7 times

Calculating Time from an Alpha Field - Using SPLIT & LENGTH

Post by DeborahMonks » Wed May 14, 2014 3:27 pm

I've been asked to calculate a time, using the 'File Opened Time' field + 30 minutes. We store the 'File Opened Time' within an Alpha field.

Below is one way of doing this; hopefully it will save you some time if you ever have to do the same!

Code: Select all

#================================== 
v-Text = ":" 
v-Time = {Case Opened Time.Text} 
#================================Split hours 
v-H = SPLIT( v-Time , 1 , 2 ) 
#================================Split minutes 
v-M = SPLIT( v-Time , 4 , 2 ) 
#================================Check if minutes >= 30 
IF v-M >= "30" THEN 
    #==============================If so, minus 30
    v-M = v-M - 30
    #==============================Check minute length
    vLen = LENGTH( V-m )
    #==============================If minute length = '1', prefix with '0'
    IF vLen = 1 THEN
        PUT( v-M , {Minutes.Text} )
        v-M = "0" + {Minutes.Text}
    END
    #==============================Add 1 to hours
    v-H = v-H +1 
    #==============================Change 24 hours to 00 
    IF v-H = "24" THEN 
        v-H = "00" 
    END
    #==============================Check hour length
    vLen = LENGTH( v-H ) 
    #==============================If hour length = '1', prefix with '0' 
    IF vLen = 1 THEN 
        PUT( v-H , {Hours.Text} ) 
        v-H = "0" + {Hours.Text} 
    END 
    #==============================Else < 30  
ELSE 
    v-M = v-M + 30 
END 
#==================== 
v-TimeNew = v-H + v-Text + v-M 
result = v-TimeNew

proclaimadmin
Site Admin
Posts: 39
Joined: Wed Nov 30, 2011 9:37 pm

Re: Calculating Time from an Alpha Field - Using SPLIT & LEN

Post by proclaimadmin » Mon May 19, 2014 3:06 pm

Thanks for your post Deborah - I'm sure this will come in useful across many casetypes

- ProclaimForum.co.uk -

Post Reply