Results 1 to 6 of 6
  1. #1
    StevenCV is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Posts
    21

    Question Time Difference When Past Midnight

    Hello,



    I have a field that works out the difference in time between two fields. However, whenever the end time goes past midnight, it calculates the difference as a minus figure. I understand that this is because of the date issue, but I cannot seem to find a way around it.

    Here is what I have so far:

    time_of_referral field. This is the start time. It is a short time field that is filled in by the end user.
    time_of_arrival field. This is the end time. It is a short time field that is filled in by the end user.
    Text31 field. This is not visible to the end user, and has the following control source =DateDiff("n",[time_of_referral],[time_of_arrival])
    Text33 field. This is an unbound text box with the following control source =[text31]\60 & Format([text31] Mod 60,"\:00")

    This works out the time difference and presents it as hours and minutes.


    I have seen solutions that add a day to the end time, but unfortunately this does not work when the end time DOESN'T go past midnight. Some will go past midnight, some won't.

    Is there a way of working this out, because this is very frustrating.

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    StevenCV is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    21
    That helps massively. A perfect solution - thank you very much!

  4. #4
    StevenCV is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    21
    I have another issue now, following on from this.

    I have another field called text35 with this control source:
    =IIf([Text31]>120,"No","Yes")

    Text31 is the hidden text box that calculated the datediff for my time - the field which is now redundant thanks to your solution above.

    How can I get text35 to say Yes or No if the time difference is over 2 hours? Can I do it by calculating on Text33, which now contains your solution?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    That expression returns elapsed time as hours:minutes. Need decimal hours. Instead of 11:15, need 11.25.

    =IIf(Val(Text33) + Right(Text33,2)/60 > 2, "No", "Yes")

    This certainly would have been simpler if the date part was saved with the time input.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    StevenCV is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    21
    June, I think you are my favourite person in the whole world. Thank you for that, it works brilliantly.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating time AT midnight
    By atom in forum Queries
    Replies: 11
    Last Post: 02-05-2012, 04:27 PM
  2. Time Difference
    By jlclark4 in forum Queries
    Replies: 4
    Last Post: 10-13-2011, 09:23 AM
  3. Date/Time Search Midnight Issue
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-26-2011, 01:54 AM
  4. working out time difference
    By moonman84 in forum Access
    Replies: 2
    Last Post: 06-29-2011, 03:33 AM
  5. Time difference
    By jguidry in forum Programming
    Replies: 1
    Last Post: 11-15-2008, 12:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums