+ Reply to Thread
Results 1 to 10 of 10

Extracting time in 60-minute increments

  1. #1
    Registered User
    Join Date
    11-17-2023
    Location
    San Jose, CA
    MS-Off Ver
    365
    Posts
    5

    Question Extracting time in 60-minute increments

    I have an excel spreadsheet with starting date and times in columns B and ending date and times in column C. Column D contains a formula that calculates the duration by subtracting column B from column C and is presented as hh:mm:ss. Columns E through AB contain hours in a day from 0 hours to 23 hours. I need help writing formulas for columns E though AB that extract the duration in column D and break down the minutes in 60-minute increments within the respective hours from column E through column AB. The date format in columns B and C is dd/mm/yyyy hh:mm:ss. Column D is column C minus column B. As an example, column B is 1/1/2018 6:15:08 and column C is 1/1/2018 9:20:00. Column D will then be 3:04:52. I expect to see 00:44:52 in column K, 00:60:00 in column L, 00:60:00 in column M, and 00:20:00 in column N. I have included a screenshot. I have tried AI and can't seem to get the right answer. Thank you for the Help!

    Screenshot 2023-11-17 123411.png

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,428

    Re: Extracting time in 60-minute increments

    Assuming that the dates and times in B, C, and row 1 are stored as numbers and not text, then number formatting won't matter to the calculation scheme. I would expect to do something like.

    1) Extract time from the Clear date time (column C), compare to the time in row 1 one column to the right (this probably means you will need a 24:00 entry in AC1), and take the smaller of the two MIN(MOD($C2,1),F$1)
    2) Extract time from the call date time (column B), compare to the time in row 1 (same column), and take the larger of the two. MAX(MOD($B2,1),E$1).
    3) Subtract 2 from 1 MIN(...)-MAX(...)
    4) When an hour is not included in the times in B and C, then this difference will be less than 0. Force it to never return a value less than 0 =MAX(0,MIN(...)-MAX(...))

    Note the mix of relative and absolute references and copy/paste/fill down and across.

    Will that work for you?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Banned User!
    Join Date
    05-13-2023
    Location
    Venera
    MS-Off Ver
    2007
    Posts
    79

    Re: Extracting time in 60-minute increments

    I have tried AI and can't seem to get the right answer.
    I every time I read this.
    Last edited by oEx; 11-17-2023 at 06:54 PM.

  4. #4
    Registered User
    Join Date
    11-17-2023
    Location
    San Jose, CA
    MS-Off Ver
    365
    Posts
    5

    Re: Extracting time in 60-minute increments

    Quote Originally Posted by MrShorty View Post
    Assuming that the dates and times in B, C, and row 1 are stored as numbers and not text, then number formatting won't matter to the calculation scheme. I would expect to do something like.

    1) Extract time from the Clear date time (column C), compare to the time in row 1 one column to the right (this probably means you will need a 24:00 entry in AC1), and take the smaller of the two MIN(MOD($C2,1),F$1)
    2) Extract time from the call date time (column B), compare to the time in row 1 (same column), and take the larger of the two. MAX(MOD($B2,1),E$1).
    3) Subtract 2 from 1 MIN(...)-MAX(...)
    4) When an hour is not included in the times in B and C, then this difference will be less than 0. Force it to never return a value less than 0 =MAX(0,MIN(...)-MAX(...))

    Note the mix of relative and absolute references and copy/paste/fill down and across.

    Will that work for you?
    Thanks MrShorty. Based on your instructions, I am using the following formula in E2 and subsequent columns, relative and absolute as applicable, but am getting zeros.

    =MAX(0,((MIN(MOD($C2,1),E$1))-MAX(MOD($B2,1),E$1)))

    Attachment 849906Screenshot 2023-11-17 164605.png
    Last edited by jaymessmythe; 11-17-2023 at 08:54 PM.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,428

    Re: Extracting time in 60-minute increments

    You missed the reference to column F in the MIN(...) portion of the formula: =MAX(0,((MIN(MOD($C2,1),F$1))-MAX(MOD($B2,1),E$1)))

  6. #6
    Registered User
    Join Date
    11-17-2023
    Location
    San Jose, CA
    MS-Off Ver
    365
    Posts
    5

    Re: Extracting time in 60-minute increments

    Quote Originally Posted by MrShorty View Post
    You missed the reference to column F in the MIN(...) portion of the formula: =MAX(0,((MIN(MOD($C2,1),F$1))-MAX(MOD($B2,1),E$1)))
    Thank you, sir, but I am still getting zeros for results.

    Screenshot 2023-11-20 080723.png

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,428

    Re: Extracting time in 60-minute increments

    It is difficult to debug a picture.

    I notice that your formula cells are all displaying 0 and not 0:00(:00). What number format have you applied to those cells? Any value 1 hour or less will display as 0 when formatted as "number with 0 decimal places." Formatted as general, there would be a value between 0 and 1/24 (0.04166...) in the cell. Make sure you are applying a suitable time (elapsed hour) format to these cells.

    The other thing that might go wrong is that the values in row 1 are text strings rather than numbers. Look at row 1 and make sure those are numbers and not text strings (=ISTEXT(E1) could be useful for this).

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

    Re: Extracting time in 60-minute increments

    Here works the formula of MrShorty perfect. See attachment:
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-17-2023
    Location
    San Jose, CA
    MS-Off Ver
    365
    Posts
    5

    Re: Extracting time in 60-minute increments

    Quote Originally Posted by MrShorty View Post
    It is difficult to debug a picture.

    I notice that your formula cells are all displaying 0 and not 0:00(:00). What number format have you applied to those cells? Any value 1 hour or less will display as 0 when formatted as "number with 0 decimal places." Formatted as general, there would be a value between 0 and 1/24 (0.04166...) in the cell. Make sure you are applying a suitable time (elapsed hour) format to these cells.

    The other thing that might go wrong is that the values in row 1 are text strings rather than numbers. Look at row 1 and make sure those are numbers and not text strings (=ISTEXT(E1) could be useful for this).
    Worked like a charm! Thank you very much. The issue was indeed formatting of the number, which is an important component of all input variables. Thank again, MrShorty!


    Unit Availability.xlsx

  10. #10
    Registered User
    Join Date
    11-17-2023
    Location
    San Jose, CA
    MS-Off Ver
    365
    Posts
    5

    Re: Extracting time in 60-minute increments

    Quote Originally Posted by HansDouwe View Post
    Here works the formula of MrShorty perfect. See attachment:
    Thanks, HansDouwe for confirming. I was indeed successful in getting the correct results after applying the correct time format.

+ 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: 5
    Last Post: 04-02-2019, 05:37 AM
  2. Replies: 2
    Last Post: 02-15-2014, 03:12 PM
  3. Excel and time calulations in 6 minute increments
    By vgsinstructor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-13-2012, 11:21 AM
  4. [SOLVED] Rounding to 6 Minute Increments for Timesheet
    By JRose0303 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-02-2012, 11:23 AM
  5. 1 - 50 calculation by 5 minute increments
    By DigiM4x in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-07-2011, 02:20 PM
  6. Replies: 5
    Last Post: 02-05-2009, 10:47 PM

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