Results 1 to 6 of 6
  1. #1
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108

    Midpoint of Two Times?

    Hi,

    Does anyone know a function I can use to calculate the midpoint between two times? (i.e. starting point, plus the total hours divided by 2)

    Examples:


    11PM to 4AM = 1:30AM

    4PM to 5PM = 4:30 PM

    7PM to 9:30PM = 8:15PM

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Something like (just an idea that you could flesh out)

    MidPoint = Time1 + Datediff("seconds",Time2 -time1)/2

    Note: I chose seconds, but you could use minutes... You could divide the seconds amount by 60 to get minutes.

    Are you using Date/Time datatypes? Can you show details of your table design?

  3. #3
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    I have two fields, one with the start time and another with the end time. e.g. "11:00:00 AM", "1:30:00 PM", etc.

    Also, I gave the DateDiff function a try, but it doesn't seem to work if the End time is after 12AM. For instance, 9P to 12A is "-1260" minutes, instead of 180.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Will get back a small test.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here's a small test.
    Code:
    Sub MyTestz()
    Dim myStartDate As Date
    Dim myEndDate As Date
    Dim midpoint As Date
    
    Dim DiffInSeconds As Long
     
    myStartDate = #6/20/2014 9:00:00 PM#
    myEndDate = #6/21/2014#  'Note this is 12:00:00 AM which is the start of the next day
     
    DiffInSeconds = DateDiff("s", myStartDate, myEndDate)  ' the difference in the times in seconds (midpoint is half)
    midpoint = DateAdd("s", (DiffInSeconds / 2), myStartDate) ' number of seconds to add to startdate
    Debug.Print "MIdpoint is " & DateAdd("s", (DiffInSeconds / 2), myStartDate)
    End Sub
    One issue is that you should include the Date as well as the Time.
    Also 9PM comes before 12AM on a shift end time, so the 12AM is really 12 AM tomorrow (or startdate + 1)

    Note I used june 20 9:00 PM and June 21 12:00 AM, but vba editor/Access drops the time(it is assuming/defaulting to 00:00:00 AM)

    Good luck.

  6. #6
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Thanks, but I don't know if that would really work for me, since I just have fields full of time values, not dates. Also, sorry, I should have specified, but do you know of a function I could apply in my query, not VBA?

    Thanks!

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

Similar Threads

  1. macros cant run more than 19 times
    By jalals in forum Programming
    Replies: 1
    Last Post: 04-16-2013, 06:38 AM
  2. Difference between Dates/Times
    By dr4ke in forum Queries
    Replies: 3
    Last Post: 06-26-2012, 06:30 AM
  3. Different between two times......
    By matthewjones108 in forum Access
    Replies: 2
    Last Post: 04-27-2012, 03:58 AM
  4. Filter between times
    By bigderon88 in forum Queries
    Replies: 1
    Last Post: 03-30-2012, 02:42 PM
  5. Top 3 times for each distance
    By CraigBFG in forum Queries
    Replies: 0
    Last Post: 06-24-2009, 09:19 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