Results 1 to 12 of 12
  1. #1
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43

    Calculating time AT midnight

    Hello everyone,



    I have come across this problem where I have to calculate time difference at midnight (e.g StartTime = 22:00 , EndTime= 00:00)

    The problem occurs when I enter EndTime :00:00 . Access converts it to 12:00 PM not AM so no matter what function I have tried to use the result is : -10

    Is there a way to solve this
    Thank you in advance

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    The end time is #12:00:00 AM#

    not :00:00.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Oh, and you should always include the date in the time calculations. It will make your life SO much easier.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,616
    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
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Quote Originally Posted by boblarson View Post
    Oh, and you should always include the date in the time calculations. It will make your life SO much easier.
    How can I do that?

  7. #7
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Thank you all for your replies great help!!

  8. #8
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    I used IIf([StartTime]>[FinishTime];(24-DateDiff("n";[FinishTime];[StartTime])/60);(DateDiff("n";[StartTime];[FinishTime]))/60).
    It workes like a charm

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by atom View Post
    How can I do that?
    I know you have it working now, but you should always use date/time fields instead of just the time. If someone logs in or out you include the date too. Then it is so very easy to use and doesn't require the formula you needed to use.

  10. #10
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    I have set the field to date/time where the user adds time but as far I can see if he double clicks date appears at 1900!Can I bypass this so that the user enters the date too?
    By now I have 2 fields for Start/Finish time and 1 field for date.

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    How does the user set the time? Is it "real time" so like they enter when they start at the time they start or do they add it in at some other time? If it is real time, then you can just have a button which adds the date and time by using NOW.
    Code:
    Private Sub YourButtonNameHere_Click()
       Me!StartDateTimeFieldNameHere = Now
    End Sub
    If at another time, you can use a date/time picker to select the date and then an unbound text box where they enter the time only and in the After Update of that text box you could use:
    Code:
    Private Sub UnBoundTextboxNameHere_AfterUpdate()
       Me!YourDateTimeFieldNameHere = Me.DatePickerNameHere.Value + Me.UnBoundTextBoxNameHere
    End Sub

  12. #12
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Yes I think this might work!
    Thank you for your help

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

Similar Threads

  1. calculating time fields
    By donnan33 in forum Programming
    Replies: 5
    Last Post: 01-19-2012, 12:15 PM
  2. Date/Time Search Midnight Issue
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-26-2011, 01:54 AM
  3. Calculating Time
    By jlclark4 in forum Forms
    Replies: 0
    Last Post: 04-25-2011, 09:04 AM
  4. Replies: 12
    Last Post: 02-22-2011, 03:39 PM
  5. Replies: 8
    Last Post: 05-24-2010, 04:24 AM

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