+ Reply to Thread
Results 1 to 17 of 17

Finding the difference between two dates with time and showing negative numbers

  1. #1
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Finding the difference between two dates with time and showing negative numbers

    I am attempting to find out how far a DVR is off on date and time. My job requires finding real time of DVR's and collecting data for them and fixing them. I'm bad at math and want a faster way of doing it. I'm developing a formula to determine any discrepancy of time on the videos. The only problem is, if the answer is negative in time, the value wont show and I get an error. Someone please help!

    video time.xlsx

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Finding the difference between two dates with time and showing negative numbers

    See if this works for you:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Finding the difference between two dates with time and showing negative numbers

    Hi there,

    Try entering the following formula in Cell C3 and copying it downwards:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding the difference between two dates with time and showing negative numbers

    Are you required to use Excel? Are you required to output the elaborate text string?

    I'm not sure why Excel has not, yet, "fixed" the "cannot display negative time" bug, but other spreadsheets have long been able to display negative times. If I open your file in LO Calc, enter the simple formula =B3-A3 into D3 (copy/paste/fill down) and format as elapsed hours [hh]:mm:ss, I get 02:12:12 in D3 and -02:12:13 in D4. If you do not have to use Excel and can tolerate a basic elapsed hours display, this can be really easy in other spreadsheets.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    I would rather not use Excel, but i'm the most familiar with it. I do have to do crazy text string after the result though to referenece the time and use it in the future as a reference

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding the difference between two dates with time and showing negative numbers

    If I had to use Excel and output that exact text string and have the information for some kind of future reference, here's how I would probably do it:

    1) In one column, calculate the basic difference between the two time stamps. =B3-C3 (format as general, if Excel automatically applies a different number format). I don't know what kind of future reference you need, but I would want this column so that, if I ever needed to reference the difference as a number that is meaningful to the spreadsheet, this column will have that number. For my testing, I put this formula into D3 (copy/paste/fill down).
    2a) In a convenient cell (I used E1), enter the text string d" days "h" hours "m" minutes "s" seconds"
    2b) In a second column (I used E3), generate the text string with something like =IF(D3>=0,"+","-")&TEXT(ABS(D3),$E$1) or something similar to the formulas given earlier in the thread.

    A lot depends on exactly what I might need for "future reference," but I would do it in 2 columns like this so that I have both the numeric "serial number" representation of the time and the text representation. The numeric representation will be useful if my "future reference" includes any needs for numeric analysis (like averaging or ranking or whatever edit: or unit conversion), and the text representation meets the requirement to have that specific text representation for users to read.

    Does that help?
    Last edited by MrShorty; 03-21-2024 at 06:08 PM.

  7. #7
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Finding the difference between two dates with time and showing negative numbers

    You could use this formula.

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


    Excel 365 (Windows) 64 bit
    A
    B
    C
    1
    Video Time
    Actual Time
    2
    Date and time Format dd/mm/yy hh:mm:ss AM/PM
    Date and time Format dd/mm/yy hh:mm:ss AM/PM
    3
    10/20/22 10:03 PM
    10/21/22 12:15 AM
    0 days 2 hours 12 minutes 12 seconds
    4
    10/21/22 12:15 AM
    10/20/22 10:03 PM
    -1 days 21 hours 47 minutes 47 seconds
    Sheet: Sheet1
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    Quote Originally Posted by DJunqueira View Post
    You could use this formula.

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


    Excel 365 (Windows) 64 bit
    A
    B
    C
    1
    Video Time
    Actual Time
    2
    Date and time Format dd/mm/yy hh:mm:ss AM/PM
    Date and time Format dd/mm/yy hh:mm:ss AM/PM
    3
    10/20/22 10:03 PM
    10/21/22 12:15 AM
    0 days 2 hours 12 minutes 12 seconds
    4
    10/21/22 12:15 AM
    10/20/22 10:03 PM
    -1 days 21 hours 47 minutes 47 seconds
    Sheet: Sheet1
    So that was the reason why the first code worked so well. The day in between 10-21 and 10-20 is not a full day, its hours... So it's doing it backwards. The top one is more correct for the time difference. I'm trying to find a way to show if its faster than the video or slower than the video.


    Here is with the original code
    video time.xlsx

  9. #9
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    See what I put above. I like the simplicity of the format, but I want it to show the hours like 2 hours away instead of a full negative day if that makes sense. I'm maybe being too difficult, but in my head ity makes sense haha.

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding the difference between two dates with time and showing negative numbers

    Unless I am missing something, I think this works (note that the file in post #8 had so many protected cells, that I chose the file in post #1 as my starting point):

    1) In D3, I enter =B3-A3 (format as general).
    2) In E1, I enter h" hours "m" minutes "s" seconds "
    3) In E3, I enter =TRUNC(D3)&" days "&TEXT(MOD(ABS(D3),1),$E$1). If I understand some of the question, I think the difference between INT() and TRUNC() is important to understand and use (see Excel's help files for documentation of the difference: https://support.microsoft.com/en-us/...4-aa5ceb292721 )
    4) In F3, I enter =CONVERT(D3,"day","sec") to convert the difference from decimal days to decimal seconds (based on the other thread that asked about converting to seconds). Select D3:F3 and copy/paste/fill down.

    I then entered a formula like =RANDBETWEEN(45000,45005)+RAND() into A6 (copy/paste/fill into A6:B25). Copy D3:E3 to row 25. Spot check results and it seems to work for days that are up to 6 days apart.

    Is that getting closer to what you want?
    Last edited by MrShorty; 03-23-2024 at 02:16 PM.

  11. #11
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    Here is an updated version. I added instructions on the cells f what i'm trying to do and how I am failing. I additionally unprotected the sheet.
    Attached Files Attached Files

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Finding the difference between two dates with time and showing negative numbers

    You didn't tell us where to look... so a guess:

    ="Video is "&IF(B4>C4,"- ","+ ")&INT(MAX(B4:C4)-MIN(B4:C4))&" days "&TEXT(MAX(B4:C4)-MIN(B4:C4),"h"" hours ""m"" minutes ""s"" seconds""")

    yellow shaded cells.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  13. #13
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    Quote Originally Posted by Glenn Kennedy View Post
    You didn't tell us where to look... so a guess:

    ="Video is "&IF(B4>C4,"- ","+ ")&INT(MAX(B4:C4)-MIN(B4:C4))&" days "&TEXT(MAX(B4:C4)-MIN(B4:C4),"h"" hours ""m"" minutes ""s"" seconds""")

    yellow shaded cells.
    Yes Column H is what I want, But I want to take it farther. H-10 is the output, but in I-9 I explain how I want to put the output in a value format so it can be referenced,

    then in J 10 I want it to be converted into seconds negative or positive. I have a formula in J and K, it puts it into secodns, but it's off and I can't figure out why.

    So the best place to start would be coverting H11 into a plain text in I 11 without doing a paste special. Then I want to take that information in J-11 and convert it to seconds with a negative integer or positive based on the output from the + or - in column H

  14. #14
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding the difference between two dates with time and showing negative numbers

    In I9, you suggest that it is necessary to convert the time difference to a complex text string in order to convert to seconds. I'm not sure why that is necessary. It seems to me that =CONVERT(C10-B10,"day","sec") should be all that is needed to convert to seconds. What am I missing?

  15. #15
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    Quote Originally Posted by MrShorty View Post
    In I9, you suggest that it is necessary to convert the time difference to a complex text string in order to convert to seconds. I'm not sure why that is necessary. It seems to me that =CONVERT(C10-B10,"day","sec") should be all that is needed to convert to seconds. What am I missing?
    My inteliigence is what is missing haha. I know what I want but may not be able to convery how I am to get it. I'm not advanced in excel, just trying to figure out something that is probably simple in a complex way. What about the hours and minutes though too?

    Ultimately I want to be able to put two different dates and times no matter how many days in between and have it spit out a text that says what I have.

    I want to take that formula and convert it into seconds so I can reference the new date and everytime I put a new time on another sheet, it will automatically add the new time with the converted seconds.

    I'm sorry if this is a coimplex way of saying it, I'm just trying to figure out the best way to explain what I need, but the formula I have is already convoluded.

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding the difference between two dates with time and showing negative numbers

    IMO, text strings are the hardest way to deal with numbers, and time stamps and time differences are just numbers (behind the number formatting). The text formatting is fine as a final output value, but I would not use it as an intermediate calculation.

    Ultimately I want to be able to put two different dates and times no matter how many days in between and have it spit out a text that says what I have (signed difference between those two date/time stamps?).
    As I noted in post #6 (and considering other things you are wanting to do, I would stick with that recommendation), I would have a column that just calculates the signed difference (=C10-B10 formatted as general) in decimal days. Then when I get to
    I can reference the new date and everytime I put a new time on another sheet, it will automatically add the new time with the converted seconds.
    I can simply put =new date/time+(cell with C10-B10). As near as I can tell, that sequence of calculations should be no more complicated than that.

    Then, you can use your "convert signed difference to text string" formulas to display the C10-B10 difference in a meaningful way (since most users are not going to know what to do with "difference is -0.091817 days"). Because you've stored the numeric meaning of that text string elsewhere, there will be no need to convert that text string back into a number.

    I've illustrated this in columns M:O of the attached. Columns M:O can do the "take the difference then add it to a new date/time stamp" steps, while your original columns can handle the "convert signed difference into a text string that is meaningful for the reader" task.

    Would it be okay to divide up responsibilities like that?
    Attached Files Attached Files
    Last edited by MrShorty; 03-26-2024 at 01:37 PM.

  17. #17
    Registered User
    Join Date
    06-28-2023
    Location
    California, United States
    MS-Off Ver
    latest
    Posts
    10

    Re: Finding the difference between two dates with time and showing negative numbers

    Thanks, this has been a side project and it's finally coming to fruition. I apprecaite all the help and will let you know my progress.

+ 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: 3
    Last Post: 11-30-2021, 12:38 AM
  2. Time difference showing in ###
    By Excelforum*ser_mH7 in forum Excel General
    Replies: 1
    Last Post: 02-25-2018, 04:36 AM
  3. Formula for the difference between positive & negative numbers
    By buyshirts in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-15-2016, 07:11 AM
  4. [SOLVED] Finding the difference between dates by using input numbers.
    By Sekars in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-28-2016, 03:01 AM
  5. Replies: 2
    Last Post: 12-08-2009, 12:21 PM
  6. Negative time should be allowed in Excel, eg time difference
    By Bengt-Inge Larsson in forum Excel General
    Replies: 2
    Last Post: 10-13-2005, 08:05 AM
  7. showing negative numbers
    By dzeitler in forum Excel General
    Replies: 2
    Last Post: 06-08-2005, 01:05 PM

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