Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting "## days, ## hours, ## minutes" string to minutes 2

Status
Not open for further replies.

Halfcan

Technical User
Dec 8, 2002
214
US
Hello,
CR V8.5, Does anyone know how to take this string and convert it to minutes?
The strings will vary:

Examples of possible data:
1. 3 days, 2 hours, 40 minutes
2. 2 hours, 40 minutes
3. 40 minutes


I'd like to convert each one down to minutes.
Any help is much appreciated, as I've got an impatient boss standing over me on this one....

Thanks,
HC
 
Something like this may work for you, if your string field always looks the way you described.
Code:
StringVar mytime := {@Hrs,Min,Sec} ;
NumberVar c := Count ( Split(mytime,"," ) ) ;
NumberVar dys:=0;
NumberVar hrs:=0;
NumberVar mns:=0;
NumberVar totmns ;
If c = 1 then
(
mns := VAL( mytime)
)
else if c = 2 then 
(
hrs := VAL( Split( mytime,"," )[1] );
mns := VAL( Split( mytime,"," )[2] );
)
else if c = 3 then 
(
dys := VAL( Split( mytime,"," )[1] );
hrs := VAL( Split( mytime,"," )[2] );
mns := VAL( Split( mytime,"," )[3] );
);

totmns := (dys * 1440) + (hrs * 60) + mns

Bob Suruncle
 
Same concept, just a little different approach:
Code:
local stringvar input := "40 minutes";
local stringvar array segments := split(input,", ");
local numbervar i;
local numbervar days := 0;
local numbervar hrs := 0;
local numbervar mins := 0;

for i := 1 to ubound(segments)
do
(
    if "days" in segments[i] then
        days := val(segments[i])
    else if "hours" in segments[i] then
        hrs := val(segments[i])
    else if "minutes" in segments[i] then
        mins := val(segments[i])
    else
        0
);
(days*1440)+(hrs*60)+mins

~Brian
 
Forgot to add that the first line should be:

local stringvar input := {table.field}; //replace with your time string field

~Brian
 
Thank you, Thank you, THANK YOU.

I am truly in debt to you both. I used Bobs formula, bdreed, I think you misunderstood my post a little bit, the 40 minutes was not a static number, just an example...when i pluged it in, i got "40 minutes" for all my records...even so, I really appreciate the help.

Thanks again,
HC
 
HC - That was why I posted the second time, since I left the static string in there from my testing.

Most important things is that you got a solution that gets you past your problem. Thanks for the star.

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top