Home > Software engineering >  TIme Separator in Google Sheets
TIme Separator in Google Sheets

Time:12-16

I hope everyone reading this is doing well. I am making attendance sheets on Google Sheets that also calculates the salary of the person. It is entirely automated except for one part, the part that calculates salaries.

For that I need to separate the Hours and Minutes worked so that I can calculate the salary accurately based on 60 minutes instead of the first half being in hours and the second from a percentage of 100.

It coverts the hours into days and omits the remaining hours. Please assist. Thank you!

What it does

What it should do

CodePudding user response:

HOUR() returns the hour component of a specific time, so it will always return a value between 0 and 23.

In Google Sheets, times are just numbers where 1 indicates 1 day. So a duration of hh:mm:ss means hh/24 mm/24/60 ss/24/60/60 which means hours_in_a_day minutes_in_a_day seconds_in_a_day. (You can see this if you format the cell as "Number")

So, if you want to extract the hours from a duration, you have to multiply it by 24 and take the INT().

=INT(B20*24)

CodePudding user response:

Spreadsheet time values such was elapsed hours are in units of days. In your spreadsheet, salary is recorded per hour. To multiply the hours by the salary, first convert the salary per hour to salary per day, and then multiply by the elapsed hours, like this:

=n((B23 * 24) * B20)

The n() wrapper is there just to get the number format right. You can also leave it out and format the formula cell as Format > Number > Currency.

See this answer for an explanation of how date and time values work in spreadsheets.

  • Related