Results 1 to 7 of 7
  1. #1
    rfigueroa1976 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2017
    Posts
    34

    Calculating variance between two dates and converting result to qty of hours

    I'm subtracting actual pickup date from requested pickup date - " Pickup Var: ([dbo_stops].[stp_arrivaldate])-([dbo_orderheader].[ord_origin_latestdate]) " to get the variance between the two. The format of both date fields is MM/DD/YY HH:MM:SS. The result of the subtraction is a decimal number... "
    1.415200197 ".
    What i'm hoping access will return is the duration of time between the two dates "
    33:57:53 "

    Long story short, can someone please help me convert a result of subtracting one date field from another as a duration between the two in hours.



    Thanks in advance.

    Tags:
    Access Change decimal number to hours
    Access convert decimal number to hours
    Access convert number to duration
    Access convert number to time

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the function DateDiff, you can get hours from that.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    =DAteDiff("h",date1,date2)

    (in dates, the integer is the day, the decimal is the time)

  4. #4
    rfigueroa1976 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2017
    Posts
    34
    This worked! However, is there a way to include minutes with the hours? Meaning, if date1 was "10/9/2017 17:15:00" and date2 was "10/10/2017 19:30:00", the calculation would show the difference of "26:15:00"

    Quote Originally Posted by ranman256 View Post
    =DAteDiff("h",date1,date2)

    (in dates, the integer is the day, the decimal is the time)

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You need to get the number of minutes with DateDiff.

    Code:
    Dim Period as Double, strElapse as String
    
    Period = DateDiff("n",date1,date2) 
    strElapse = Int(Period/60) & ":" & (Period / 60 - Int(Period / 60)) * 60

  6. #6
    rfigueroa1976 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2017
    Posts
    34
    I don't understand (I'm a novice). Can you please right it out in formula format so that i can copy and paste?



    Quote Originally Posted by aytee111 View Post
    You need to get the number of minutes with DateDiff.

    Code:
    Dim Period as Double, strElapse as String
    
    Period = DateDiff("n",date1,date2) 
    strElapse = Int(Period/60) & ":" & (Period / 60 - Int(Period / 60)) * 60

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    DateDiff("n", [date1], [date2]) \ 60 & Format(DateDiff("n", [date1], [date2]) Mod 60, "\:00")

    Source: http://allenbrowne.com/casu-13.html

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

Similar Threads

  1. Subtract 8 hours of work from result hours
    By alhareri in forum Queries
    Replies: 6
    Last Post: 12-02-2014, 08:25 AM
  2. Replies: 8
    Last Post: 12-02-2013, 03:46 PM
  3. Calculating future Hours for Employees
    By bluke in forum Queries
    Replies: 1
    Last Post: 08-21-2013, 01:39 PM
  4. Converting minutes into hours in report
    By jinro in forum Access
    Replies: 13
    Last Post: 04-01-2013, 07:06 PM
  5. Converting Minutes Into Hours
    By KellyM in forum Reports
    Replies: 8
    Last Post: 04-23-2012, 12:49 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