+ Reply to Thread
Results 1 to 9 of 9

Sleep duration in 24 h format

  1. #1
    Registered User
    Join Date
    03-27-2022
    Location
    Hamburg, Germany
    MS-Off Ver
    2203 (Microsoft 365 Apps for Enterprise)
    Posts
    7

    Unhappy Sleep duration in 24 h format

    Dear people!

    For a psychological survey I am trying to calculate the sleep duration of people.
    My problem is that it doesn't work if the sleep end is a smaller number than the sleep onset. For example a sleep duration from 22.00 - 08.00.
    I was planning to use a fictional date with my formula in the end being "=IF(C3<B3;(A3+1+C3)-(A3+B3);(C3-B3))" as you can see in the attachment.
    Can anyone see what the problem is? I'm clueless...

    Thanks in advance and best regards

    Winston from Hamburg, Germany
    Attached Files Attached Files
    Last edited by zillinger; 03-30-2022 at 05:15 AM. Reason: attachment was missing

  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,424

    Re: Calculating sleep duration in 24h time format

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    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
    Registered User
    Join Date
    03-27-2022
    Location
    Hamburg, Germany
    MS-Off Ver
    2203 (Microsoft 365 Apps for Enterprise)
    Posts
    7

    Re: Sleep duration in 24 h format

    Thanks! Edited!

  4. #4
    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,424

    Re: Sleep duration in 24 h format

    Your formula should work, but it could be shorter

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

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


    The problem is that not all the times in column C are true times. They are all right aligned but that is due to the formatting, not because they are numeric. Easy way is to select each cell and press F2 and Enter. Or you can use Text to Columns.

  5. #5
    Forum Contributor
    Join Date
    11-05-2020
    Location
    England
    MS-Off Ver
    365
    Posts
    155

    Re: Sleep duration in 24 h format

    Let me know how the below works for you:

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


    To be copied into cell D10
    Last edited by Farley945; 03-30-2022 at 03:12 AM.

  6. #6
    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,424

    Re: Sleep duration in 24 h format

    This seems to work with your original data without transforming it:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Sleep duration in 24 h format

    One way:

    =MOD(C3-B3;1)

  8. #8
    Registered User
    Join Date
    03-27-2022
    Location
    Hamburg, Germany
    MS-Off Ver
    2203 (Microsoft 365 Apps for Enterprise)
    Posts
    7

    Re: Sleep duration in 24 h format

    It worked!
    Thanks so much to everyone for their effort!
    I used the second formula by TMS! Much appreciated!

    Greetings from Hamburg!

  9. #9
    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,424

    Re: Sleep duration in 24 h format

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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] need to format date time and calculate duration
    By esaji in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-14-2021, 02:05 PM
  2. Cell format for duration not time
    By matt_c_l in forum Excel General
    Replies: 4
    Last Post: 09-26-2018, 04:17 PM
  3. VBA calculate sleep time, when time is entered in military time format
    By axm1955 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-29-2017, 10:28 AM
  4. Calculating overlapping time interval period during a certain duration
    By Mukund03 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-26-2015, 01:08 PM
  5. Calculating duration with strange date / time format
    By chrispx001 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-12-2013, 11:08 AM
  6. calculating total payment - Time duration x Hourly Rate
    By sobiafiaz in forum Excel General
    Replies: 3
    Last Post: 10-06-2007, 05:24 PM
  7. Calculating Sleep
    By CarlM in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 08-03-2006, 08:45 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