Question DateDiff Problem

AccessNewBoy

Registered User.
Local time
Today, 07:29
Joined
Mar 11, 2009
Messages
19
Hello all,
as you can see from my user id i am new to Access so any support you can give me would be great as i need it.

I have created a countdown counter on a form using different Datediff's so to split the renaining time into days, hours, minutes and seconds.
The Datediff compares Now() to a text box called txt.Leaving which has a date/time unputted via a table (Format: General Date)

However the seconds and minutes work ok but the hours and days dont count down inline with the minutes and seconds reducing. The hours do alter when the minutes are 13 mins into the new hour. This would seem to point possibly to rounding off but I would expect that further into the hour.

Below is the Datediff that is set as the control source in a text box and the form it sits on has its timer set to 1000 and the event requeries the text box.

=DateDiff("d",Now(),[txt.Leaving]) & "d, " & DateDiff("h",Now(),[txt.Leaving]) Mod 24 & "h, " & DateDiff("n",Now(),[txt.Leaving]) Mod 60 & "m, " & DateDiff("s",Now(),[txt.Leaving]) Mod 60 & "s"

I would be greetful for any help.

PS Using Access 2000.
 
Last edited:
I'm not sure DateDiff() is your best bet here. Consider this data and code...
Code:
Sub Test1038469807()
   Dim d1 As Date
   Dim d2 As Date
   
   d1 = #8/1/2012 11:59:59 PM#
   d2 = #8/2/2012 12:00:01 AM#
   
   Debug.Print DateDiff("d", d1, d2) & "d, " & DateDiff("h", d1, d2) Mod 24 & "h, " & DateDiff("n", d1, d2) Mod 60 & "m, " & DateDiff("s", d1, d2) Mod 60 & "s"
End Sub
...and the output is...
Code:
1d, 1h, 1m, 2s
...which is pretty wildly wrong, since the dates are only two seconds apart.

I'd probably get the interval, in seconds, between the two dates, and then see how many days fit into that number of seconds, then subtract those seconds from the interval, then see how many hours fit into what is left, then subtract those seconds, and so on. Do you get what I'm saying?

Mark
 
Lagbolt,
thanks for support but already tried to work the Datediff's from seconds and to take all other results from the interval. The issue is still the same, i feel the issue is due to the Datediff being refreshed each second. If i just use two fixed dates and keep changing them the results are correct each time but as a running count down the problems start. I have even tried to split days, hours, minutes and seconds into seperate Text boxes but the problem still happens.

I will keep looking through the forums but all i seem to see is people saying "check previous forum questions on subject"

Thank you
 

Users who are viewing this thread

Back
Top Bottom