Help
cancel
Showing results for
Did you mean:
Highlighted
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?

Thanks

2 Replies
Solution
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```

-Gabriele-

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

Highlighted
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:

`=DATE(YEAR(L39),MONTH(L39),DAY(L39)-1)+TIME(HOUR(L39),MINUTE(L39),SECOND(L39))`

Formula in N39:

`=L39-L41`

Final Formula in Cell L43:

`=DATE(YEAR(L41),MONTH(L41),DAY(L41))+(N39-L40)+TIME(HOUR(L41),MINUTE(L41),SECOND(L41))`

N.B:

• 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.

Rajesh S.

New solutions

Top Kudoed Posts