Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 3

Maths problem: time calculation

Solved! Go to Solution.

I need some math for a formula to do the following:


User inputs the:

number of hours sleep they want

time they want to wake up

I return the time they need to go to bed.


I am using a calculator plug in that does not have any time functions. So if wake up time is 8 and they want 14 hours sleep I get a -6. Any thoughts on the formual to use so -6 would be 18:00?



2 Replies
Commander Lvl 2
Message 2 of 3

Re: Maths problem: time calculation

Hi @JCA2626,


Welcome to the Github Community Forum!


The basic formula is this gbt = (24 - hts + wut) module 24, with: gbt the go bed time, hts the hours the user want to sleep and wut the wake up time.

In your example will be something like this:


wake_up_time = userInput() = 8
hours_to_sleep = userInput() = 14
go_bed_time = (24 - hours_to_sleep + wake_up_time) mod 24 = (24 - 14 + 8) mod 24 = 18 mod 24 = 18


Hope to solve your problem, ask if have more question :)




Mark helpfull posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great contents!

Ground Controller Lvl 2
Message 3 of 3

Re: Maths problem: time calculation

Hi, @JCA2626 ,, also using Excel this can be solved.


Formula in Cell L 41:




Formula in N39:



Final Formula in Cell L43:





  • Cell Format in L39, L41 & L43 is mm/dd/yy HH:MM:SS AM/PM.
  • Keep changing Wakeup Time & Hours to sleep to find New Bed Time.


Hope this help you.


Rajesh S.