I have saved a duration in minutes and want to have an output "1 day 5 hours 30 minutes". Currently i add the minutes to a Timespan and do something like this:
TimeSpan ts = new TimeSpan(0,0,1800, 0);
Response.Write(ts.Days + "day(s) " + ts.Hours + " hour(s)" + ts.Minutes + " minutes");
But now i am only interested in the working-hours of a day. So when the duration of the TimeSpan is 27 Hours it should not create the output "1 Day 3 Hours". I want to have "3 Days 3 Hours".
Is there maybe an easy way to do that with the Timespan object? Is it possible to change the default behaviour of the TimeSpan? Or do i have to program my own custom Timespan-Class?
Thx cpt.oneeye
Can you simply use:
(int)(ts.TotalHours / 8)
instead of ts.Days
? Then use
(((int)ts.TotalHours) % 8)
instead of ts.Hours
.
You need to implement something like this:
TimeSpan workday = new TimeSpan(8, 0, 0);
int workdays = ts.Ticks / workday.Ticks
TimeSpan rest = new TimeSpan(ts.Ticks % workday.Ticks)
Response.Write(workdays + "workday(s) and" + rest.ToString());
Will write something like
"3 workday(s) and 3:32"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With