+ Reply to Thread
Results 1 to 16 of 16

Excel 2007 : Finding the difference in time

  1. #1
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Finding the difference in time

    Hello,

    I'm new here and I've been browsing through various forums and tutorials on how to subtract time stamps in order to find the time difference.

    I appear to be having a formatting issue that I just can't solve.

    A1: 1/11/2009 0:1:00 (Essentially November 1st, 2009 at 1 AM) - End Date
    B1: 07/10/2009 14:35 (October 7th, 2009 at 2:35 PM) - Start Date
    (both fields have been formatted as "dd/mm/yyyy h:mm")

    To find the the time difference I subtract A1 from B1 and the general formatting result I get is -269.5665394, for almost any type of date formatting I choose I get an infinite amount of ###s or if I use [h], I will get -6469.

    I think it may be reading the End date as January 11th instead of November 1st but I can't seem to format it properly. Could anyone shed any light on this issue?

    PS: The end date was previously a time range formatted like 1/11/2009 01:00 - 02:00, since I wanted the just the beginning instance I removed 8 characters through A1=LEFT(A2,LEN(A2)-8). I believe that this also may be the cause of the formatting issue because I cannot format the field as "1-Nov-09".

    Thanks!
    Last edited by peter_f; 10-08-2010 at 03:37 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Finding the difference in time

    Hi and welcome to the board.
    To make sure, can you post a small example of your data?

  3. #3
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Quote Originally Posted by arthurbr View Post
    Hi and welcome to the board.
    To make sure, can you post a small example of your data?
    Thanks for the welcome.

    I'm not sure what you mean by a small example but I pulled out some data points and attached it in a separate excel file.
    sample_timedifference.xlsx

    I came to a partial solution by how I formatted the End Date Window into an instance through the following formula

    =TEXT(LEFT(A15,LEN(A15)-8),"dd/mm/yyyy h:mm")

    However, the results show that the month/day is being read wrong, BUT I'm getting the correct time difference result (for once).

    However, a new issue appears and in some cases, the time difference will show a "#VALUE" error.

    I'm quite confused by the process of what I've done and how it works for some cases but not all of them.

    Any help would be greatly appreciated.

  4. #4
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    I just realized that this was more of a general excel question; Is there any chance a moderator could move this thread to "Excel General"?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    If you go to Regional Settings in your Windows Control Panel can you tell us which Region is active ?

    The regional setting impacts the way date strings are interpreted by Excel - we need to know which it is - sounds like it might be US rather than Canada.

  6. #6
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Quote Originally Posted by DonkeyOte View Post
    If you go to Regional Settings in your Windows Control Panel can you tell us which Region is active ?

    The regional setting impacts the way date strings are interpreted by Excel - we need to know which it is - sounds like it might be US rather than Canada.
    Everything is set to US (Language for non-Unicode programs,Standards and formats, and even Location).

    Hope that helps.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    I am hoping dll will conjure up something more succinct but if we assume that both day & month values can be both single / double digit (eg 1/1/2009, 1/11/2009, 11/1/2009) then:

    Please Login or Register  to view this content.
    I would add to this the fact that formatting resulting in terms of days hours & minutes is a risk given days can not be displayed cumulatively beyond 31 days.

    better to display either in decimal form (ie format as General) or use [h]:mm

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Finding the difference in time

    You could try this version to get the time difference in row 3

    =SUBSTITUTE(MID(LEFT(A3,LEN(A3)-8),FIND("/",A3)+1,99),"/","/"&LEFT(A3,FIND("/",A3)))-C3
    Audere est facere

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    grrrrr.... ... I feel like Baron von Greenback dealing with Danger Mouse ... did you know BvG is aka as Avram Grant ?

  10. #10
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Thanks guys, the formulas almost work perfectly. But I'm having difficulty with two particular records (out of 100s of successful ones) and I'm still not sure why.

    I tried both formulas from DonkeyOte and Daddylongleg but when the formula comes across these two records: Daddylongleg's formula will generate a time difference of "#VALUE" and DonkyOte's formula's generated value will be incorrect.

    I've attached a file demonstrating the formula's working for another record but not working for the two troublesome ones.

    sample_timedifference v2.xlsx

    Thanks in advance!

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    You should find that if you replace:

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    in dll's formula it will work (and remain the more efficient option)

  12. #12
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Hi DonkeyOte,

    Using that modification to DLL's formula will fix the "#VALUE" issue but I'm also unsure about the actual results
    for example if I'm comparing end date 9/11/2009 with start date 6/11/2009; I should have a time difference of approximately 3 days. However, in these two records I'm getting something close to 150 days. It would appear that it's reading these two records start date as MM/DD/YYYY which was kind of the issue in the first place.

    This data set has been giving me an odd amount of problems for just formatting.
    Since it's only two records, it's something I can probably manually calculate but it still bothers me just a bit (in cases where I might run across the same issue).

    Any ideas?

  13. #13
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    The date values in C20:C23 are all Jun 2009 rather than Nov 2009 which you're implying
    (the values in C15:C16 being Oct 2009)

  14. #14
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Quote Originally Posted by DonkeyOte View Post
    The date values in C20:C23 are all Jun 2009 rather than Nov 2009 which you're implying
    (the values in C15:C16 being Oct 2009)
    I just checked the End Date Range field again and I think I realize the issue.
    The formula to change the End Date Range into a the End Date Instance is only for ranges that are within the the same date.

    For example: 8/11/2009 08:00 - 18:00 (length: 23)

    However, for these two problem records they have End Date Ranges that span multiple dates
    IE: 9/11/2009 04:00 - 12/11/2009 22:00.

    I think the best way around this would be to make a condition such as
    =if(len(A1)=23, DLL modified formula for single date ranges, new formula for the multidate range).

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding the difference in time

    No, that's not the issue.
    The multiple date strings were the cause of the #VALUE! errors you reported earlier for which a fix was provided (post #11)

    The cause of the "unexpected" results is simply that your dates in C20:C23 are in fact June 2009 and not November 2009 as it would seem you believe them to be based on expected results you outline.
    This was the point made in post # 13

    To confirm this apply: =MONTH(C20) and you should find the value returned is 6 as opposed to 11

    Conversely the same formula is applied to C15 will return 10

    The confusion stems from the fact different number formats have been applied to the date values in Column C - some are displaying as dd/mm and others as mm/dd
    The results generated by the formula are correct based on the date values in Column C and the strings in A.

    edit: the above is all based on sample file provided in post # 10
    Last edited by DonkeyOte; 10-08-2010 at 02:58 PM.

  16. #16
    Registered User
    Join Date
    10-07-2010
    Location
    waterloo, on
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Finding the difference in time

    Quote Originally Posted by DonkeyOte View Post
    No, that's not the issue.
    The multiple date strings were the cause of the #VALUE! errors you reported earlier for which a fix was provided (post #11)

    The cause of the "unexpected" results is simply that your dates in C20:C23 are in fact June 2009 and not November 2009 as it would seem you believe them to be based on expected results you outline.
    This was the point made in post # 13

    To confirm this apply: =MONTH(C20) and you should find the value returned is 6 as opposed to 11

    Conversely the same formula is applied to C15 will return 10

    The confusion stems from the fact different number formats have been applied to the date values in Column C - some are displaying as dd/mm and others as mm/dd
    The results generated by the formula are correct based on the date values in Column C and the strings in A.

    edit: the above is all based on sample file provided in post # 10
    I think I have made two big mistakes:
    1) The sample file posted in #10 was incorrectly made (formatting of start date)
    2) The correct solution in post #11 was applied to the incorrect sample file leading to more confusion on my part.

    Good news is I think all is well!
    Thanks for all your help DonkeyOte; (you were several steps ahead of me).

    Regards,
    Peter

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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