+ Reply to Thread
Results 1 to 13 of 13

calculate difference in time

  1. #1
    Registered User
    Join Date
    02-13-2020
    Location
    Cyprus
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    calculate difference in time

    The attached spreadsheet contains 7 columns. Columns B and C contain a date and a time.

    I need to calculate the difference in time between columns B and C and put it in column H. I don't care about the date or the seconds, I just need the time difference in minutes. For example:

    if the time in column B is 1:30 and the time in column C is 2:32 I want column H to say 62.

    How can this be done?
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: calculate difference in time

    Here is a power Query solution

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-13-2020
    Location
    Cyprus
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: calculate difference in time

    forgot to mention that I am using google sheets. I don't think power query is supported

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: calculate difference in time

    One way and custom format cells [mm]:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: calculate difference in time

    Will move this to the Google sub forum so there will be no confusion

  6. #6
    Forum Contributor
    Join Date
    12-17-2013
    Location
    ON, Canada
    MS-Off Ver
    MS 365
    Posts
    171

    Re: calculate difference in time

    in cell H2, put the following formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Format H2: Format > Number > Custom number format > [m]

  7. #7
    Registered User
    Join Date
    02-13-2020
    Location
    Cyprus
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: calculate difference in time

    Quote Originally Posted by Flyboy65 View Post
    in cell H2, put the following formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Format H2: Format > Number > Custom number format > [m]
    it just says #VALUE!

    1.png

  8. #8
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: calculate difference in time

    Did you see post #4?

  9. #9
    Registered User
    Join Date
    02-13-2020
    Location
    Cyprus
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: calculate difference in time

    Quote Originally Posted by HansDouwe View Post
    Did you see post #4?
    yes, for some reason, the result is #VALUE!

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

    Re: calculate difference in time

    It appears to me you have the same problem so many others have with dates in spreadsheets. Your dates are not numbers, they are text strings [=is text(B2) returns true]. This leaves you at the whims and mercy of the spreadsheet you're using how it will interpret these text strings, if it even chooses to interpret the text as a number. As an example of these whims, my copy of Sheets has no trouble with Flyboy's simple formula. I suspect that is because my regional settings are such that Sheets is able to recognize these as NDY dates and convert correctly to number, but you settings don't allow Sheets to see that these are dates.

    You haven't said anything about your data entry/import process. IMO, the best thing you could do is figure out how to enter/import the data so it will be permanently stored as a number. That might mean changing regional settings or changing to DMY dates in the source text file or something else. If you will enter/import your dates as numbers and not text, you will have a much easier time working with those values.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  11. #11
    Registered User
    Join Date
    02-13-2020
    Location
    Cyprus
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: calculate difference in time

    Quote Originally Posted by MrShorty View Post
    It appears to me you have the same problem so many others have with dates in spreadsheets. Your dates are not numbers, they are text strings [=is text(B2) returns true]. This leaves you at the whims and mercy of the spreadsheet you're using how it will interpret these text strings, if it even chooses to interpret the text as a number. As an example of these whims, my copy of Sheets has no trouble with Flyboy's simple formula. I suspect that is because my regional settings are such that Sheets is able to recognize these as NDY dates and convert correctly to number, but you settings don't allow Sheets to see that these are dates.

    You haven't said anything about your data entry/import process. IMO, the best thing you could do is figure out how to enter/import the data so it will be permanently stored as a number. That might mean changing regional settings or changing to DMY dates in the source text file or something else. If you will enter/import your dates as numbers and not text, you will have a much easier time working with those values.
    The data is coming from an integration platform called integrately. The spreadsheet serves as a log file, showing the result of the operations performed by the automation. Indeed =istext(B2) returns TRUE. I did change the formatting of the cells to Number but that had no effect. Is there a way I can change the settings of the sheet to recognise the entries as NDY dates?

  12. #12
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: calculate difference in time

    the result is #VALUE!
    Sorry, the cell reference was not correct, please try this formula ande copy down:

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

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

    Re: calculate difference in time

    Is there a way I can change the settings of the sheet to recognise the entries as NDY dates?
    I don't have much experience with Sheets, but this essay mentions that, "To ensure correct calculations, it's vital to have the correct locale set." [emphasis mine] https://www.ablebits.com/office-addi...e-date-format/ If you are going to store "dates as text" and receive those dates in an MDY type of format, it will be important to change the spreadsheet's locale settings to something that will readily accept MDY dates.

    The other choice might be, since you know where the data are coming from, is to go into Integrately and have Integrately output the log file time stamps in a format more compatible with your default locale settings. Again, while I have limited experience with Sheets, what experience I have suggests that Sheets may automatically import and store dates as numbers rather than text if the date strings in the text file match Sheets' locale settings.

+ 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. [SOLVED] calculate time difference based on date and time in different cells
    By s7yzrs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2022, 06:22 AM
  2. Calculate time difference between Date/Time fields
    By mattfleet in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-09-2019, 06:43 PM
  3. [SOLVED] how to calculate the time difference between each timestamp and a time total
    By HenrikSS in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-17-2018, 06:44 AM
  4. Replies: 3
    Last Post: 03-02-2012, 08:18 PM
  5. Calculate the time difference
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2010, 06:31 AM
  6. In and out time difference calculate
    By Rahul Nagar in forum Excel General
    Replies: 2
    Last Post: 06-12-2009, 01:19 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