how can I take total minutes from time?

My system displayed the time like this 10:42 when i input the command date +%R. I need to take in total minutes of the time. That means like this 642 minutes. Is there any command or shell script for displaying total time in minutes?


To only get the total minutes of the day, I would use the following command:

$ date "+%H*60+%M" | bc

Example:

$ date +%R
09:30
$ date "+%H*60+%M" | bc
570

The trick is to format the date output to allow bc to interpret and calculate the formula.


just bash:

IFS=: read hour min < <(date +%R)
echo $(( 60 * 10#$hour + 10#$min ))

Forcing both variables to be treated as base-10, to avoid the shell throwing errors for invalid octal numbers 08 and 09