+ Reply to Thread
Results 1 to 22 of 22

Time calculations

  1. #1
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Time calculations

    Been here at my desk for two days trying to find a formula that will calculate the difference between two times. I've tried multiple formulas and been online for hours and can't get one formula that will work for all. Anybody have a minute to take a look, please and thanks?
    Attached Files Attached Files
    Last edited by BDD2015; 10-17-2018 at 06:34 PM. Reason: 2nd file added

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: Time calculations

    I have attempted to attach file with formula. Check it out and reply. thx

    in cell C5 place the following formula: =IF(A5>B5,TEXT(A5-B5,"h:mm:ss")&" Before",TEXT(B5-A5,"h:mm:ss")) . The "Before" stands for 'actually departed BEFORE the Scheduled departure. (Please note, your dates are not date formats....they are text (the above formula will work). Reminder: please post whether or not this had assisted you. thx
    Attached Files Attached Files
    Last edited by queuesef; 10-18-2018 at 03:02 PM. Reason: attempt to attach file

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: Time calculations

    Hi

    The following formula should work

    IF(ISBLANK(B5),"Not Sent",IF(A5>B5,A5-B5,B5-A5))

    Format col C under custom format h:mm

    Cheers

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Time calculations

    As queuesef pointed out above, your problem is that the dates/times you have are actually text, not dates/times as Excel understands them. The easiest way to deal with this is to first convert them to actual dates/times and then to do the calculation. To do this, add two 'helper' columns - insert new columns C and D between your current columns B and C. Then put this in the new C2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Then this in the new D2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Drag down both columns.
    Note that both formulae assume that the text-formatted dates/times are always formatted as mm/dd/yyyy[space]hh:mm - in other words, with two-digit months and days, and using the American mm/dd format not the international dd/mm format.

    Now the calculation in Col E (your old Col C) is fairly simple - subtract one time from the other, using an IF formula to check which time is later. The formula below will return just the time difference if the actual departure is later or equal to the scheduled, and will add ' early' if the actual time is earlier. Format the column with the custom number format [h]:mm.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Note that the formula above changes the figure to text if the dep. was early, so if you want to do calculations with the numbers, it might be better to just have the number (i.e. the time diff) and put another column to note whether the actual dep is earlier or later. Put these two formulae in E2 and F2, then drag down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Hope that helps. Attached is a file showing it working - two sheets, with the two options for showing late/early.
    Attached Files Attached Files
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  5. #5
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Time calculations

    Hi,

    Although OP's Columns A and B and Text values and Not Real Date/Time values, once we do arithmetic with the data, it will automatically convert to Real Date/Time values.
    Since OP did not specify How he/she wants the results, I've included 2 versions:

    If you Only want to see the Time difference, use this in C2 copied down, format Column C custom [h]:mm:ss

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then, use this in D2 copied down to indicate "On Time", "Early", or "Late" if desired:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you want the time difference And the indicator whether it was "On Time", "Early", or "Late" all in a Single cell, then use this in C2 copied down, Column C then formatted General

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    No helper columns needed, see attached.

    Edit: added extra formula option.
    Attached Files Attached Files
    Last edited by jtakw; 10-17-2018 at 03:42 PM.

  6. #6
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi, queuesef. Unfortunately I just get #value errors. I've tried multiple formatting changes and I still get the errors.

  7. #7
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi jtakw. Thanks for popping in. Perfect example of why I "hate" Excel. Sometimes it doesn't make sense. Your spreadsheet is great. Thank you. But when I apply the formula to the spreadsheet I attached I get #value errors. And col C is formatted as custom [h]:mm:ss

    And even when I copy your formula (which works) into another col. I still get the #value errors. And again it is custom [h]:mm:ss.
    Last edited by BDD2015; 10-17-2018 at 06:25 PM.

  8. #8
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Time calculations

    That's strange..., cause the spreadsheet I uploaded in Post # 5 Is your spreadsheet in OP (I just added my formulas)...

    Can you upload a new one where you're getting the #VALUE errors?

  9. #9
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi, Aardigspook. Works perfectly. Thank you!

  10. #10
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Done. Thanks. Hate these kinds makes no sense glitches.

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Time calculations

    Put a 1 in D1, copy
    Select A5:C42, Pastespecial, multiply, format as "hh:mm:ss"
    C5: =ABS(B5-A5)
    Attached Files Attached Files
    Ben Van Johnson

  12. #12
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi, Ben. Works excellent as well. Reason for the 1 and ... Did it. Works. Used the formula without that step and appears to work as well. Little confused.

  13. #13
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Time calculations

    Quote Originally Posted by BDD2015 View Post
    Done. Thanks. Hate these kinds makes no sense glitches.
    Just downloaded the second file in OP, Columns C, E, F show #VALUE errors, But, as soon as I click "Enable Editing", All values are calculated correctly.

  14. #14
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    And it continues... Strange. I know the button you mention but I don't get it when I open the file. And I've looked through all the Options. I'll keep looking. Sigh...

  15. #15
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Time calculations

    Try downloading the 2nd file from your OP yourself...

  16. #16
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Jtakw - Did. Still not getting the enable editing button. Excel hates me.

  17. #17
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Jtakw. But when I use your formulas in another workbook, they work. Too tired to figure this out tonight. Thanks so much for your help. I'll be back at 'er in the early am. Might be back here... lol
    Last edited by BDD2015; 10-17-2018 at 07:31 PM.

  18. #18
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Time calculations

    When you get a chance, perhaps check and make sure Calculations are on Automatic for the workbook that's having #VALUE errors.
    File->Options->Formulas->Automatic

  19. #19
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Time calculations

    I get #Value errors with all the suggested solutions as well - that's why I went the long-winded helper columns & conversion route in post 4. I'm guessing the problems are something to do with Regional Settings, as it's the members from outwith the USA who seem to be getting #Value errors whilst those from the USA aren't.

  20. #20
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi,
    So, had checked all Options last night and everything looked ok. Opened it at work today and no Enabling Button there either. But - converted the Scheduled and Actual dates to numbers and Voila. No more #Value errors. So all is good! Thanks so much for your help and patience.

  21. #21
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Time calculations

    Hi, again

    I think it has to do with whether it's text or a number. When I convert the dates, one of your columns works but not the other. It's been a really long day and my brain is shutting down but I will solve this mystery. Thanks so much for your help last night. If I do indeed figure it out I'll let you know.

  22. #22
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Time calculations

    Assuming your settings use dd/mm/yyyy date format, it would be very dangerous to use simple subtractions on text values. For example, the difference between 10/09/2018 23:45 and 10/10/2018 00:04 is almost 700 hours with UK settings, which I suspect is not the intention. And of course, when the day number goes over 12, you'll just see #VALUE! errors.
    Rory

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 02-14-2018, 03:52 PM
  2. [SOLVED] Extract a time from a cell with date and time stamp and then perform calculations
    By Marcos Aristotelous in forum Excel General
    Replies: 3
    Last Post: 10-31-2012, 04:36 AM
  3. date time calculations - elapsed time
    By jo3llen in forum Excel General
    Replies: 3
    Last Post: 07-11-2011, 01:43 PM
  4. Time Calculations:On-Time Performance
    By rmcquar in forum Excel General
    Replies: 1
    Last Post: 10-07-2010, 06:42 PM
  5. Time Calculations:length of time
    By KDaney in forum Excel General
    Replies: 1
    Last Post: 08-23-2010, 12:36 PM
  6. [SOLVED] convert time imported as text to time format for calculations
    By batfish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2005, 07:05 PM
  7. [SOLVED] Time calculations
    By Neville in forum Excel General
    Replies: 3
    Last Post: 09-21-2005, 06:05 AM

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