DateDiff Hoours and Minutes (1 Viewer)

ddrew

seasoned user
Local time
Today, 22:01
Joined
Jan 26, 2003
Messages
911
Can somebody please show me where I'm going wriong here. Im trying to calculate the number of hours and minutes that have passed.
Code:
Me.ElapsedTime = DateDiff("h", EventStartTime.Column(1), EventTinishTime.Column(1))
With this it rounds down to the nearest hour, I wnat to show hours and minutes. I know I have to put"n" in there somewhere, just not shure where!:confused:
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Sep 12, 2006
Messages
15,692
i presume this will work

do date diff with a n qualifier (n=minutes, not m=month)

this should give you the total minutes.

now elapsed hours will be minutes/60
elapsed minutes will be minutes mod 60
 

ddrew

seasoned user
Local time
Today, 22:01
Joined
Jan 26, 2003
Messages
911
i presume this will work

do date diff with a n qualifier (n=minutes, not m=month)

this should give you the total minutes.

now elapsed hours will be minutes/60
elapsed minutes will be minutes mod 60

Humm, somethings not right! If I set the EventStartTime at 10:00 and the EventFinishTime as 11:15 I get 1.25 which is right as an equation but not as elapsed time:confused:
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Sep 12, 2006
Messages
15,692
yes it is - you are evaluating hours

1hr 15mins is 1.25 hours.

-----
as i said, evaluate minutes - then you will get 75
 

ddrew

seasoned user
Local time
Today, 22:01
Joined
Jan 26, 2003
Messages
911
yes it is - you are evaluating hours

1hr 15mins is 1.25 hours.

-----
as i said, evaluate minutes - then you will get 75

OK, clearly I'm not understanding at the minute! This is my code now
Code:
Me.ElapsedTime = DateDiff("h", EventStartTime.Column(1), EventTinishTime.Column(1))
asnd as you said I get 75, thats fine. But I want it to show 1.15
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:01
Joined
Sep 12, 2006
Messages
15,692
and i said, you need to get the 75 minutes -

then you can show the hours and minutes

totalminutes = datediff ("n", etc)

elapsedtime = totalminutes/60 & ":" & totalminutes mod 60
or maybe
elapsedtime = int(totalminutes/60) & ":" & totalminutes mod 60
 

ddrew

seasoned user
Local time
Today, 22:01
Joined
Jan 26, 2003
Messages
911
and i said, you need to get the 75 minutes -

then you can show the hours and minutes

totalminutes = datediff ("n", etc)

elapsedtime = totalminutes/60 & ":" & totalminutes mod 60
or maybe
elapsedtime = int(totalminutes/60) & ":" & totalminutes mod 60

Think I understand. I created an Unbound TextBox to hold the totalminutes (not sure if that was the right thing to do or not) then built in:
Code:
 Me.ElapsedTime = Me.totalminutes / 60 & ":" & totalminutes Mod 60
the result that I got was. 1.25:15 So I used
Code:
elapsedtime = int(totalminutes/60) & ":" & totalminutes mod 60
and I got 1:15 :)
 
Last edited:

ddrew

seasoned user
Local time
Today, 22:01
Joined
Jan 26, 2003
Messages
911
One furthur thing, how should I deal with situations when the time goes past 00:00 i.e Start time 20:30 Finish time 00:30 at the minute I get -20:0 for that!
 

r.harrison

It'll be fine (I think!)
Local time
Today, 22:01
Joined
Oct 4, 2011
Messages
134
Hi,

You would need to use an if statement.

if StartTime > Finishtime then elapsedtime=elapsedtime+24

or something similar.
 

Users who are viewing this thread

Top Bottom