By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Calculation of time

P: n/a
Hi all

I am trying to calculate the two different time field. When I entered
in field like 7:00 and 15:00 the result is 8 hrs but when I entered
15:30 the result is also 8 hrs. I am using the following VBA code

Private Sub TimeToDay_AfterUpdate()

'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60

End Sub

Please help me to solve this problem.

Thanks in advance.

Naushad
Feb 18 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You'll need to format your [TotDay] control to display at least 1 decimal
place to see fractions of an hour, i.e. 1.45 hours. If you want to display
your time result as hrs:min, then you'll need to roll-your-own format.
-Ed
<nh*****@kockw.comwrote in message
news:09**********************************@q70g2000 hsb.googlegroups.com...
Hi all

I am trying to calculate the two different time field. When I entered
in field like 7:00 and 15:00 the result is 8 hrs but when I entered
15:30 the result is also 8 hrs. I am using the following VBA code

Private Sub TimeToDay_AfterUpdate()

'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60

End Sub

Please help me to solve this problem.

Thanks in advance.

Naushad

Feb 18 '08 #2

P: n/a
Ed Robichaud wrote:
You'll need to format your [TotDay] control to display at least 1 decimal
place to see fractions of an hour, i.e. 1.45 hours. If you want to display
your time result as hrs:min, then you'll need to roll-your-own format.
-Ed
Expanding on what you wrote...
ts = #7:00#
te = #15:30#
? timeserial(0,datediff("n",ts,te),0)
8:30:00 AM
? Format(timeserial(0,datediff("n",ts,te),0),"h.n")
8.30

The number to the right of the decimal point is in minutes, not a
decimal equivalent.

Creeps
http://www.youtube.com/watch?v=aUgTCpLJOEU&NR=1
>
<nh*****@kockw.comwrote in message
news:09**********************************@q70g2000 hsb.googlegroups.com...
>>Hi all

I am trying to calculate the two different time field. When I entered
in field like 7:00 and 15:00 the result is 8 hrs but when I entered
15:30 the result is also 8 hrs. I am using the following VBA code

Private Sub TimeToDay_AfterUpdate()

'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60

End Sub

Please help me to solve this problem.

Thanks in advance.

Naushad


Feb 18 '08 #3

P: n/a
On Feb 18, 8:09*pm, Salad <o...@vinegar.comwrote:
Ed Robichaud wrote:
You'll need to format your [TotDay] control to display at least 1 decimal
place to see fractions of an hour, i.e. 1.45 hours. * If you want to display
your time result as hrs:min, then you'll need to roll-your-own format.
-Ed

Expanding on what you wrote...
ts = #7:00#
te = #15:30#
? timeserial(0,datediff("n",ts,te),0)
8:30:00 AM
? Format(timeserial(0,datediff("n",ts,te),0),"h.n")
8.30

The number to the right of the decimal point is in minutes, not a
decimal equivalent.

Creepshttp://www.youtube.com/watch?v=aUgTCpLJOEU&NR=1


<nhai...@kockw.comwrote in message
news:09**********************************@q70g2000 hsb.googlegroups.com...
>Hi all
>I am trying to calculate the two different time field. When I entered
in field like 7:00 and 15:00 the result is 8 hrs but when I entered
15:30 the result is also 8 hrs. I am using the following VBA code
>Private Sub TimeToDay_AfterUpdate()
>'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
>End Sub
>Please help me to solve this problem.
>Thanks in advance.
>Naushad- Hide quoted text -

- Show quoted text -
Hi Creep

I did [TotDay] control to display at least 1 decimal place to see
fractions of an hour and expanded my code as per your suggestion but
the result is same i.e. the whole no. not fraction.

Please help me to solve this problem.

Naushad
Feb 21 '08 #4

P: n/a
On Wed, 20 Feb 2008 22:44:32 -0800 (PST), nh*****@kockw.com wrote:
>>
<nhai...@kockw.comwrote in message
news:09**********************************@q70g200 0hsb.googlegroups.com...
>>Hi all
>>I am trying to calculate the two different time field. When I entered
in field like 7:00 and 15:00 the result is 8 hrs but when I entered
15:30 the result is also 8 hrs. I am using the following VBA code
>>Private Sub TimeToDay_AfterUpdate()
>>'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
>>End Sub
>>Please help me to solve this problem.
>>Thanks in advance.
>>Naushad- Hide quoted text -

- Show quoted text -

Hi Creep

I did [TotDay] control to display at least 1 decimal place to see
fractions of an hour and expanded my code as per your suggestion but
the result is same i.e. the whole no. not fraction.

Please help me to solve this problem.

Naushad
Is the TotDay control bound to a field? Possibly an integer field?

Perhaps you should look at the formatting of your control again.

?(datediff("n",#7:00#,#15:00#)-30)/60
7.5

What's with that "- 30"? It looks as though someone might be
intending some sort of rounding.
Feb 21 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.