Let's say I have two std::string that have two different times like so
12:05:02
12:20:02
in the HH:MM:SS format
how can I go about getting and storing how many minutes have passed between the two sets of time ? For example, a total of 15 minutes have passed between those two given times.
int seconds_since_midnight( std::string t ) // format is hh:mm:ss (24 hr clock)
{ return std::stoi(t) * 60*60 + std::stoi( t.substr(3) ) * 60 + std::stoi( t.substr(6) ) ; }
int elapsed_completed_minutes( std::string from, std::string to ) // format is hh:mm:ss (24 hr clock)
{
constauto a = seconds_since_midnight(from) ;
auto b = seconds_since_midnight(to) ;
if( b < a ) b += 24*60*60 ; // period crosses over midnight
return (b-a) / 60 ;
}