Sum Fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my database I have 2 fields "FirstDelayEnd" and "FirstDelayStart" these
are date and time fields I have a third field called "FirstDelayTotal" with
this formula in the control source
=TimeDuration([FirstDelayEnd]-[FirstDelayStart]) (I have VB to get the
correct time format) and it works great. I have the same for the "Second" and
"Third" delays and they work fine. But when I =Sum(First+Second+Third) I get
1:202:253:10 (First was 1:20, Second was 2:25 and Third was 3:10) instead of
5:55 what am I doing wrong. I'm am new at all this so I don't know much.
 
tankerman said:
In my database I have 2 fields "FirstDelayEnd" and "FirstDelayStart" these
are date and time fields I have a third field called "FirstDelayTotal"
with
this formula in the control source
=TimeDuration([FirstDelayEnd]-[FirstDelayStart]) (I have VB to get the
correct time format) and it works great. I have the same for the "Second"
and
"Third" delays and they work fine. But when I =Sum(First+Second+Third) I
get
1:202:253:10 (First was 1:20, Second was 2:25 and Third was 3:10) instead
of
5:55 what am I doing wrong. I'm am new at all this so I don't know much.

Surely appears that you are concatenating text, rather than summing
anything.

There's no Time variable, so if you think that's what you're using, you are
actually using Date/Time... that would be Dec. 30, 1899 01:20AM, Dec. 30,
1899 02:25AM, and Dec. 30, 1899 03:10AM. Or, possibly Dec. 30, 1899
00:01:20AM, Dec. 30, 1899 00:02:25AM, and Dec. 30, 1899 00:03:10AM.

The DateDiff function properly handles subtracting two dates... it returns
the difference as an Integer or Long Integer in the units you specify. In an
Access 2003 code window, VBA Help on DateDiff is good. DateAdd allows you to
add various time or date units to a Date, but that's not what you are doing.

What you need to do is to calculate the delays in the time unit of your
choice, seconds, minutes, or hours, then display it in a format that you
desire. Assuming your time calculations represent 1 hour, 20 minutes; 2
hours, 25 minutes; and 3 hours, 10 minutes, you could keep them in minutes
as 80, 145, and 190. A little integer division calculation would let you
calculate the hours and minutes for display.

Larry Linson
Microsoft Access MVP
 
Tankerman,

Going by your nick in conjunction with the question, are you talking about
oil tankers (as in shipping) demurrage calculation?
If so, I can help, otherwise please ignore my replay

Regards
Jacob
 
Larry, Yes I am using hours and minutes and it seems to always come back with
the correct hours and minutes between the two fields. Here is the VB I use

Public Function TimeDuration(dblDuration As Double) As String
Const HOURSINDAY = 24
Dim strDays As String
Dim strMinutes As String

'get number of days
strDays = Int(dblDuration) * HOURSINDAY + _
Format(dblDuration, "h")

' get minutes
strMinutes = Format(dblDuration, ":nn")

TimeDuration = strDays & strMinutes

End Function

JK, Yes I am trying to figure the delays we have in pumping or loading
barges at different facilities, delays are chargable to a facility or to the
barge dependiing on reason for the delay and length of the delay. In my
database the reason for the delays are entered with the dates and times in
seperate fields so we can accurately track the hours and minutes of each
delay as well as the total of the delays because we are having some
facilities shutting us down 2 or 3 different times for a various reason. We
are trying to track the reasons as well to see if there is a patteren to the
delays.

JK said:
Tankerman,

Going by your nick in conjunction with the question, are you talking about
oil tankers (as in shipping) demurrage calculation?
If so, I can help, otherwise please ignore my replay

Regards
Jacob



tankerman said:
In my database I have 2 fields "FirstDelayEnd" and "FirstDelayStart" these
are date and time fields I have a third field called "FirstDelayTotal"
with
this formula in the control source
=TimeDuration([FirstDelayEnd]-[FirstDelayStart]) (I have VB to get the
correct time format) and it works great. I have the same for the "Second"
and
"Third" delays and they work fine. But when I =Sum(First+Second+Third) I
get
1:202:253:10 (First was 1:20, Second was 2:25 and Third was 3:10) instead
of
5:55 what am I doing wrong. I'm am new at all this so I don't know much.
 
Tankerman,

I am well familiar with what you are trying to accomplish, albeit in
ocean-going vessels the approach is different. My suggesttion is to do the
caluclation in lines of:

Delay=EndDelay-StartDelay (use your field names) and use the function below
to dipsplay it correctly:

+++++
Private Function FormatTime( _
tmNumber As Double, _
Optional strSeparator As String = ":", _
Optional inclSuffix As Boolean = False, _
Optional dispDays As Boolean = False) As String
'-------------------------
'Return a string with time format, allowing more then
'31 days or more than 24 hours

'****Does NOT allow for Seconds

'Written by JK
'Plaese Feel free to use with or without acknowledgment
'but it would be appreciated if you acknowlege the Newsgroup

'---------------------------------------

'Parameters:
'Examples are based on 2 days 15 hours 30 minutes

'tmNumber: Time Number, 1= 1 day, example=2.645833333
'strSparator: Time saparator eg ":" eg 02:15:30
'InclSuffix: Add suffix to time e.g.
' 02d:15h:30m (no option to change suffix)
'displayDays: If Fales, dispaly day in hours, eg.
' 02d:15h:30m = 63h:30m


Dim tmpNum As Double, _
tmpDD As Long, _
tmpHH As Long, _
tmpMM As Long, _
strDD As String, _
strHH As String, _
strMM As String, _
isNeg As Boolean

'tmpNum: Temprary storage
'tmp/StrDD: How days are displayed, if at all
'tmp/strHH: Number of hours to display
' depending on dispalyDays
'tmp/strMM: Number of Minutes
'isNeg: Negtive time indicator

tmpNum = tmNumber
isNeg = IIf(tmpNum < 0, True, False)
tmpNum = Abs(tmpNum)
tmpDD = Int(tmpNum)
tmpNum = (tmpNum - Int(tmpNum)) * 24
tmpHH = Int(tmpNum)
tmpHH = tmpHH + IIf(dispDays, 0, tmpDD * 24)
tmpNum = (tmpNum - Int(tmpNum)) * 60
tmpMM = Round(tmpNum, 0)

If tmpMM = 60 Then
tmpMM = 0
tmpHH = tmpHH + 1
End If


If dispDays Then
strDD = IIf(tmpDD <= 9, "0", "") _
& Trim(Str(tmpDD)) _
& IIf(inclSuffix, "d", "") _
& strSeparator
Else
strDD = ""
End If

strHH = IIf(tmpHH <= 9, "0", "") _
& Trim(Str(tmpHH)) _
& IIf(inclSuffix, "h", "") _
& strSeparator

strMM = IIf(tmpMM <= 9, "0", "") _
& Trim(Str(tmpMM)) _
& IIf(inclSuffix, "m", "")

FormatTime = IIf(isNeg, "-", " ") _
& strDD & strHH & strMM

End Function

++++

I hple this is of help

Regards
Jacob






tankerman said:
Larry, Yes I am using hours and minutes and it seems to always come back
with
the correct hours and minutes between the two fields. Here is the VB I use

Public Function TimeDuration(dblDuration As Double) As String
Const HOURSINDAY = 24
Dim strDays As String
Dim strMinutes As String

'get number of days
strDays = Int(dblDuration) * HOURSINDAY + _
Format(dblDuration, "h")

' get minutes
strMinutes = Format(dblDuration, ":nn")

TimeDuration = strDays & strMinutes

End Function

JK, Yes I am trying to figure the delays we have in pumping or loading
barges at different facilities, delays are chargable to a facility or to
the
barge dependiing on reason for the delay and length of the delay. In my
database the reason for the delays are entered with the dates and times in
seperate fields so we can accurately track the hours and minutes of each
delay as well as the total of the delays because we are having some
facilities shutting us down 2 or 3 different times for a various reason.
We
are trying to track the reasons as well to see if there is a patteren to
the
delays.

JK said:
Tankerman,

Going by your nick in conjunction with the question, are you talking
about
oil tankers (as in shipping) demurrage calculation?
If so, I can help, otherwise please ignore my replay

Regards
Jacob



tankerman said:
In my database I have 2 fields "FirstDelayEnd" and "FirstDelayStart"
these
are date and time fields I have a third field called "FirstDelayTotal"
with
this formula in the control source
=TimeDuration([FirstDelayEnd]-[FirstDelayStart]) (I have VB to get the
correct time format) and it works great. I have the same for the
"Second"
and
"Third" delays and they work fine. But when I =Sum(First+Second+Third)
I
get
1:202:253:10 (First was 1:20, Second was 2:25 and Third was 3:10)
instead
of
5:55 what am I doing wrong. I'm am new at all this so I don't know
much.
 
With pleasure

tankerman said:
Jacob thanks for the VB it works great, I am able to get the correct time
in
hours and minutes. Thanks again.

JK said:
Tankerman,

I am well familiar with what you are trying to accomplish, albeit in
ocean-going vessels the approach is different. My suggesttion is to do
the
caluclation in lines of:

Delay=EndDelay-StartDelay (use your field names) and use the function
below
to dipsplay it correctly:

+++++
Private Function FormatTime( _
tmNumber As Double, _
Optional strSeparator As String = ":", _
Optional inclSuffix As Boolean = False, _
Optional dispDays As Boolean = False) As String
'-------------------------
'Return a string with time format, allowing more then
'31 days or more than 24 hours

'****Does NOT allow for Seconds

'Written by JK
'Plaese Feel free to use with or without acknowledgment
'but it would be appreciated if you acknowlege the Newsgroup

'---------------------------------------

'Parameters:
'Examples are based on 2 days 15 hours 30 minutes

'tmNumber: Time Number, 1= 1 day, example=2.645833333
'strSparator: Time saparator eg ":" eg 02:15:30
'InclSuffix: Add suffix to time e.g.
' 02d:15h:30m (no option to change suffix)
'displayDays: If Fales, dispaly day in hours, eg.
' 02d:15h:30m = 63h:30m


Dim tmpNum As Double, _
tmpDD As Long, _
tmpHH As Long, _
tmpMM As Long, _
strDD As String, _
strHH As String, _
strMM As String, _
isNeg As Boolean

'tmpNum: Temprary storage
'tmp/StrDD: How days are displayed, if at all
'tmp/strHH: Number of hours to display
' depending on dispalyDays
'tmp/strMM: Number of Minutes
'isNeg: Negtive time indicator

tmpNum = tmNumber
isNeg = IIf(tmpNum < 0, True, False)
tmpNum = Abs(tmpNum)
tmpDD = Int(tmpNum)
tmpNum = (tmpNum - Int(tmpNum)) * 24
tmpHH = Int(tmpNum)
tmpHH = tmpHH + IIf(dispDays, 0, tmpDD * 24)
tmpNum = (tmpNum - Int(tmpNum)) * 60
tmpMM = Round(tmpNum, 0)

If tmpMM = 60 Then
tmpMM = 0
tmpHH = tmpHH + 1
End If


If dispDays Then
strDD = IIf(tmpDD <= 9, "0", "") _
& Trim(Str(tmpDD)) _
& IIf(inclSuffix, "d", "") _
& strSeparator
Else
strDD = ""
End If

strHH = IIf(tmpHH <= 9, "0", "") _
& Trim(Str(tmpHH)) _
& IIf(inclSuffix, "h", "") _
& strSeparator

strMM = IIf(tmpMM <= 9, "0", "") _
& Trim(Str(tmpMM)) _
& IIf(inclSuffix, "m", "")

FormatTime = IIf(isNeg, "-", " ") _
& strDD & strHH & strMM

End Function

++++

I hple this is of help

Regards
Jacob






tankerman said:
Larry, Yes I am using hours and minutes and it seems to always come
back
with
the correct hours and minutes between the two fields. Here is the VB I
use

Public Function TimeDuration(dblDuration As Double) As String
Const HOURSINDAY = 24
Dim strDays As String
Dim strMinutes As String

'get number of days
strDays = Int(dblDuration) * HOURSINDAY + _
Format(dblDuration, "h")

' get minutes
strMinutes = Format(dblDuration, ":nn")

TimeDuration = strDays & strMinutes

End Function

JK, Yes I am trying to figure the delays we have in pumping or loading
barges at different facilities, delays are chargable to a facility or
to
the
barge dependiing on reason for the delay and length of the delay. In my
database the reason for the delays are entered with the dates and times
in
seperate fields so we can accurately track the hours and minutes of
each
delay as well as the total of the delays because we are having some
facilities shutting us down 2 or 3 different times for a various
reason.
We
are trying to track the reasons as well to see if there is a patteren
to
the
delays.

JK" wrote:

Tankerman,

Going by your nick in conjunction with the question, are you talking
about
oil tankers (as in shipping) demurrage calculation?
If so, I can help, otherwise please ignore my replay

Regards
Jacob



In my database I have 2 fields "FirstDelayEnd" and "FirstDelayStart"
these
are date and time fields I have a third field called
"FirstDelayTotal"
with
this formula in the control source
=TimeDuration([FirstDelayEnd]-[FirstDelayStart]) (I have VB to get
the
correct time format) and it works great. I have the same for the
"Second"
and
"Third" delays and they work fine. But when I
=Sum(First+Second+Third)
I
get
1:202:253:10 (First was 1:20, Second was 2:25 and Third was 3:10)
instead
of
5:55 what am I doing wrong. I'm am new at all this so I don't know
much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Inserting SSD to new kit 1
SUM FUNCTION 1
Populate a table 2
Hour Calculation 2
QUERY FIELD SUM 14
Field content auto generation? 7
Sum Group By 2
Third Quartile 3

Back
Top