+ Reply to Thread
Results 1 to 4 of 4

Computing for Elapsed Time, in Hours

  1. #1
    Registered User
    Join Date
    04-29-2012
    Location
    Juperos Elevator
    MS-Off Ver
    Excel 2007
    Posts
    10

    Unhappy Computing for Elapsed Time, in Hours

    Hello!
    I want to know which code to use if I want to find out the total time between two Now()s, in hours (example, if 90 mins have passed, the output would be 1.5). Here's my original code:
    Please Login or Register  to view this content.
    Where label6.caption and label3.caption are set to now() if a button is clicked.
    This code returns "0"

    extra question: what others ways of searching/looking up data in sheets besides this one
    Please Login or Register  to view this content.
    can you suggest? This method almost always returns the "Unable to get match/vlookup/index property of the Worksheet Function class" Error.

    Thank you very much for your help, have a nice day! :D

  2. #2
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Computing for Elapsed Time, in Hours

    1: You could use date arithmetic:

    Label4.Caption = format((cdate(label3.caption)-cdate(label6.caption))*24,"#0.0")

    2: It might be better to split it up a bit, for troubleshooting:

    Please Login or Register  to view this content.
    With the row number in hand (or not), you can refer to the cell directly.

  3. #3
    Registered User
    Join Date
    04-29-2012
    Location
    Juperos Elevator
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Computing for Elapsed Time, in Hours

    Thank you for the codes! :D I don't know why the first one still returns "0"

  4. #4
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Computing for Elapsed Time, in Hours

    It looks like the datediff function wants to return an integer. So with "h", it will never give you the 1.5 you were looking for. You could use "n" (minutes):

    totaltime = round(DateDiff("n", Label6.Caption, Label3.Caption)/60,1)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1