calculating hours/time

K

kimla10

How do i calculate time ; hours worked ? I am trying to find a field code
formula in a Word table and then to minus that by 0.30? I have designed a
Timesheet but want to calculate daily hours then minus it by lunch break.
Can anyone help?

I have seen time calculations but i can't find time as in hours worked.
 
M

macropod

Hi kimla10,

Although it can be done in Word, Excel is a far better tool for this. And, in Word, a macro is probably going to give you a better
solution than a field code. Here's some code recently posted recently by Jay Freedman, another Microsoft Word MVP:

Sub demo()
Dim startTime As Date, endTime As Date
Dim diffHr As Long, diffMin As Long
startTime = CDate("8:00 am")
endTime = CDate("12:35 pm")
diffMin = Abs(DateDiff("n", startTime, endTime))
diffHr = Int(diffMin / 60) ' truncated to whole hours
diffMin = diffMin Mod 60 ' remaining minutes
MsgBox diffHr & ":" & diffMin
End Sub

To make this work in your table, you'd need to get the startTime & endTime from formfields with their properties set to run the
macro on exit, then output the result to another field instead of to the message box.

Having said all the above, if you *really* want to go down the field code route, you can how to do this and just about everything
else you might want to do with dates in Word, check out my Date Calc 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
or
http://www.gmayor.com/downloads.htm#Third_party

Cheers
 
H

Henk57

Excel is better equipped for this. If you want it in Word, eg if you
need to make a weekly report, you can link the Excel table to the word
document so it automatically updates in Word once changed in Excel.

macropod;2433439 said:
Hi kimla10,

Although it can be done in Word, Excel is a far better tool for this.
And, in Word, a macro is probably going to give you a better
solution than a field code. Here's some code recently posted recently
by Jay Freedman, another Microsoft Word MVP:

Sub demo()
Dim startTime As Date, endTime As Date
Dim diffHr As Long, diffMin As Long
startTime = CDate("8:00 am")
endTime = CDate("12:35 pm")
diffMin = Abs(DateDiff("n", startTime, endTime))
diffHr = Int(diffMin / 60) ' truncated to whole hours
diffMin = diffMin Mod 60 ' remaining minutes
MsgBox diffHr & ":" & diffMin
End Sub

To make this work in your table, you'd need to get the startTime &
endTime from formfields with their properties set to run the
macro on exit, then output the result to another field instead of to
the message box.

Having said all the above, if you *really* want to go down the field
code route, you can how to do this and just about everything
else you might want to do with dates in Word, check out my Date Calc
'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
or
http://www.gmayor.com/downloads.htm#Third_party

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"kimla10" [email protected] wrote in message
How do i calculate time ; hours worked ? I am trying to find a field
code
formula in a Word table and then to minus that by 0.30? I have
designed a
Timesheet but want to calculate daily hours then minus it by lunch
break.
Can anyone help?

I have seen time calculations but i can't find time as in hours
worked. -
 
K

kimla10

Thanks very very much. I did think that it was better in Excel but i didn't
know i could link the two. Thanks a bunch. I am very grateful for the info.
Kimla10

Henk57 said:
Excel is better equipped for this. If you want it in Word, eg if you
need to make a weekly report, you can link the Excel table to the word
document so it automatically updates in Word once changed in Excel.

macropod;2433439 said:
Hi kimla10,

Although it can be done in Word, Excel is a far better tool for this.
And, in Word, a macro is probably going to give you a better
solution than a field code. Here's some code recently posted recently
by Jay Freedman, another Microsoft Word MVP:

Sub demo()
Dim startTime As Date, endTime As Date
Dim diffHr As Long, diffMin As Long
startTime = CDate("8:00 am")
endTime = CDate("12:35 pm")
diffMin = Abs(DateDiff("n", startTime, endTime))
diffHr = Int(diffMin / 60) ' truncated to whole hours
diffMin = diffMin Mod 60 ' remaining minutes
MsgBox diffHr & ":" & diffMin
End Sub

To make this work in your table, you'd need to get the startTime &
endTime from formfields with their properties set to run the
macro on exit, then output the result to another field instead of to
the message box.

Having said all the above, if you *really* want to go down the field
code route, you can how to do this and just about everything
else you might want to do with dates in Word, check out my Date Calc
'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
or
http://www.gmayor.com/downloads.htm#Third_party

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"kimla10" [email protected] wrote in message
How do i calculate time ; hours worked ? I am trying to find a field
code
formula in a Word table and then to minus that by 0.30? I have
designed a
Timesheet but want to calculate daily hours then minus it by lunch
break.
Can anyone help?

I have seen time calculations but i can't find time as in hours
worked. -
 
Top