Time difference for leave application (1 Viewer)

gsrajan

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 22, 2014
Messages
227
Please let me know what is syntax to get the total time used in hours and minutes:

1. Start time: 9.30 am
End time: 5.00 pm
I need to get used time as 7.50 ( that is 71/2 hours)

2. Start time: 9.30 am
End time: 5.30 pm
I need to get used time as 8.00

Thanks for your help.
 

gsrajan

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 22, 2014
Messages
227
Thanks so much.
 

gsrajan

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 22, 2014
Messages
227
Thanks so much.
I tried this:

Start time: 10.30 A.M. End time 12.00 P.M.
I get the output 2. Not 1.5.

This is my code:

txtTotal = DateDiff("n", [StartTime], [EndTime]) / 60

Thank you.
 

Minty

AWF VIP
Local time
Today, 00:25
Joined
Jul 26, 2013
Messages
10,366
I don't know why , in the immediate window if I type

? DateDiff("n", DATE(), Now()) / 60

I get

20.6666666666667

Did you define txtTotal as an integer?
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:25
Joined
Sep 21, 2011
Messages
14,231
What type is txtTotal?
Code:
starttime = #10:30 AM#
endtime= #12:00 PM#
txtTotal = DateDiff("n", StartTime, EndTime) / 60
? txttotal
 1.5
 

gsrajan

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 22, 2014
Messages
227
Yes, I tried your above code and tried this also. Getting same result. Not sure why. Thanks for trying.

Dim myInt As Integer
myInt = DateDiff("n", StartTime, EndTime) / 60
txtTotal = myInt
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:25
Joined
Sep 21, 2011
Messages
14,231
Yes, I tried your above code and tried this also. Getting same result. Not sure why. Thanks for trying.

Dim myInt As Integer
myInt = DateDiff("n", StartTime, EndTime) / 60
txtTotal = myInt
How on earth do you expect to get a value like 1.5 when you are using an integer type? :unsure:
 

gsrajan

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 22, 2014
Messages
227
:) I just said apart from the code your provided, this is also not working. Can you please tweak it if you can? thanks
 

Minty

AWF VIP
Local time
Today, 00:25
Joined
Jul 26, 2013
Messages
10,366
An integer data type can only store a integer value - a whole number.
Pick a data type that has some decimal portion;

Dim MyResult as Currency
MyResult = DateDiff("n", StartTime, EndTime) / 60
 

Users who are viewing this thread

Top Bottom