cancel
Showing results for 
Search instead for 
Did you mean: 

Formula for time elapsed -- in hours and minutes

Former Member
0 Kudos

I need a formula that will give me the time elapsed in hours and minutes. The hours may be over a two-day period -- starting sometime before midnight on one date; and ending sometime on the next date. Hope you can help. Thanks in advance. I love you guys.

Kathryn.

Accepted Solutions (1)

Accepted Solutions (1)

former_member260594
Active Contributor
0 Kudos

Hello Kathryn,

Try this formula;

numbervar b:= datediff( 's', , );

numbervar i;

numbervar n;

i:= truncate( b/3600);

n:= if b <> i3600 then remainder( b, (i3600))/ 60 else 0'

totext(i,0) + ':' + totext(n,0)

Variable i will calculate the hours while n will output the minutes. The datediff is done in seconds so that it will round up to the nearest minute.

Former Member
0 Kudos

Thank you for the help. I typed the formula exactly as shown, but got an error message saying the remaining text does not appear to be part of the formula after the i: on the 4th line.

Did I get something wrong? Sorry to trouble you.

Former Member
0 Kudos

Update:

I had a typo in the 4th line, and have now progressed to the 5th line -- where I have a new error.

On the 5th line: the letter "i" is highlighted and the error says "The keyword then is missing".

I tried adding the "then", but that results in a message saying that the remaining text does not appear to be part of the formula.

Sorry about my typo on line 4. Do you have any ideas on how I can get past line 5?

Former Member
0 Kudos

replace that line with:

n:= if b <> i3600 then remainder( b, (i3600))/ 60 else 0;

if b NOT EQUAL TO i*3600, the not equal sign (less than and great than signs) might be missing, plug that in if missing.

Former Member
0 Kudos

Try this:


numbervar b:= datediff( 's', {startdatefield}, {enddatefield});
numbervar i;
numbervar n;

i:= truncate( b/3600);
n:=(b mod 3600)/60;
totext(i,0) + 'hrs:' + totext(n,0) + 'min'

Regards,

Zack H.

Former Member
0 Kudos

Tried that but still can't get past the "i" on the 5th line. The error message still says it needs a "then" ??

Former Member
0 Kudos

did you just put in the NOT EQUAL sign and that's it? You need to delete the last quote after zero and also put in a semi colon.

Former Member
0 Kudos

Sanjay is trying to tell you to do the following to make the original post by Graham work for you.


numbervar b:= datediff( 's', {startdatefield}, {enddatefield});
numbervar i;
numbervar n;

i:= truncate( b/3600);
n:= if b &lt;&gt; i*3600 then remainder( b, (i*3600))/ 60 else 0;
totext(i,0) + ':' + totext(n,0)

I hope this helps,

Regards,

Zack H.

Former Member
0 Kudos

Thanks, everyone! That did it!! You guys are awesome!!!

Answers (0)