-5

Need to count in C# app, minutes in SLA to show in format :

N working days, N working hours, N working minutes

current code show up only hours:minutes format:

TimeSpan spWorkMin = TimeSpan.FromMinutes(12534);
string workHours = string.Format("{0}:{1:00}", (int)spWorkMin.TotalHours, spWorkMin.Minutes);
Console.WriteLine(workHours);
DarthCSharper
  • 133
  • 1
  • 13

2 Answers2

1

Here is the code to show the timespan in number of days, hours, minutes:

TimeSpan spWorkMin = TimeSpan.FromMinutes(12534);
string workHours = $"{spWorkMin.Days} working days, {spWorkMin.Hours} working hours, {spWorkMin.Minutes} working minutes";
Console.WriteLine(workHours);
Eriawan Kusumawardhono
  • 4,796
  • 4
  • 46
  • 49
Alberto Santos
  • 357
  • 1
  • 9
1

I am not sure what you want to achieve, but in every usual day, you get 3 business days.

var numberOfDays = minutes/60/24;
var numberOfBusinessDays = numberOfDays/3;
var numberOfBusinessHours = (numberOfBusinessDays - Math.Truncate(numberOfBusinessDays))*24;
var numberOfBusinessMinutes = (numberOfBusinessHours - Math.Truncate(numberOfBusinessHours)*60;

Then you can truncate decimal part from all of the results

int numberOfBusinessDaysToInt = Math.Truncate(numberOfBusinessDays);
int numberOfBusinessHoursToInt = Math.Truncate(numberOfBusinessHours);
int numberOfBusinessMinutesToInt = Math.Truncate(numberOfBusinessMinutes);
Piotr Moreń
  • 126
  • 5