not sure whats wrong with time calculation

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

Guest

Me.duration_txt = ([findate_txt] + [fintime_txt]) - ([startdate_txt] + [starttime_txt]

Where the foramating is as follows: duration_txt is short time, findate_txt is short date, startdate_txt is short date, and starttime_txt is short time

now if we say ([04/04/2004] + [23:00]) - ([04/03/2004] + [23:00]) then the duration_txt should be 24:00hrs (elapsed time). but it is showing up as 0:0

I just can not see where the problem, I'm hopping that someone can shed some light.
 
If the Format on [duration_txt] is Short Time (?) or simimlar, then the
dispaly is correct since 24 hrs is 1 day plus 0:00 and the Formnat will
display only 0:00.

I would suggest to use DateDiff in your code to work out the difference in
minutes and then convert (by code) to whatever format you want to display,
e.g. hh:mm. This way, you can display more than 24 hrs.

--
HTH
Van T. Dinh
MVP (Access)


Derek said:
Me.duration_txt = ([findate_txt] + [fintime_txt]) - ([startdate_txt] + [starttime_txt])

Where the foramating is as follows: duration_txt is short time,
findate_txt is short date, startdate_txt is short date, and starttime_txt is
short time.
now if we say ([04/04/2004] + [23:00]) - ([04/03/2004] + [23:00]) then
the duration_txt should be 24:00hrs (elapsed time). but it is showing up as
0:00
I just can not see where the problem, I'm hopping that someone can shed
some light.
 
I didn't think that I could use datediff here as I was adding the time to
the date first. Would I just use the following:

datefiff (([findate_txt] + [fintime_txt]) , ([startdate_txt] +
[starttime_txt]))

With the duration field formated as short time, or would I ecapsulate the
above in: format (....,"hh:nn")?

Van T. Dinh said:
If the Format on [duration_txt] is Short Time (?) or simimlar, then the
dispaly is correct since 24 hrs is 1 day plus 0:00 and the Formnat will
display only 0:00.

I would suggest to use DateDiff in your code to work out the difference in
minutes and then convert (by code) to whatever format you want to display,
e.g. hh:mm. This way, you can display more than 24 hrs.

--
HTH
Van T. Dinh
MVP (Access)


Derek said:
Me.duration_txt = ([findate_txt] + [fintime_txt]) - ([startdate_txt] + [starttime_txt])

Where the foramating is as follows: duration_txt is short time,
findate_txt is short date, startdate_txt is short date, and starttime_txt is
short time.
now if we say ([04/04/2004] + [23:00]) - ([04/03/2004] + [23:00]) then
the duration_txt should be 24:00hrs (elapsed time). but it is showing up as
0:00

I just can not see where the problem, I'm hopping that someone can shed
some light.
 
Your syntax for DateDiff is incorrect. Check Access Help for correct use.

Like I wrote in the my previous post, the DateDiff will give you the number
of minutes and you use code to convert it to "hh:mm" since the time formats
will NOT allow you to display more than 24 hours.

Code should be something like:

Dim lngMinutes As Long

lngMinutes = DateDiff ("n", ([findate_txt] + [fintime_txt]) , _
([startdate_txt] +[starttime_txt]))

Me.TextBox = lngMinutes \ 60 & ":" & Format(lngMinutes MOD 60, "00")
 
Back
Top