Question

I'm creating simple table report with column of TimeSpan type. I'm summing its values, which leads into values bigger than 24 hours, into Text componnent.

{SumTime(DataBand1,Records.time)}

I'm trying to format Text field like HH:mm:ss, but for 25 hours it gives me 01:00:00 (or 1.01:00:00 with general formatting) instead of 25:00:00 what is my goal.

Edit: The problem is not how to format timespan, but how to associate formatted value into Stimulsoft's Text component.

Was it helpful?

Solution

The Hours property has a maximum of 24h. You could format it yourself using String.Format and TimeSpan.TotalHours:

string text = string.Format("{0}:{1}:{2}",
                     (int) Records.time.TotalHours, // TotalHours is double
                     Records.time.Minutes,
                     Records.time.Seconds);

OTHER TIPS

I know this is kind of an old question, but I stumbled upon it looking for a solution myself. Having done some digging, here's what I've come up with:

Assuming you already have a timespan variable (either setting it in the datasource, or having a variable set with DateDiff), you can format it with the following:

{string.Format("{0}:{1}:{2}", 
                (int) Variable1.TotalHours, 
                 Variable1.Minutes,
                 Variable1.Seconds)}

Lets say you have two different fields (named Date1 and Date2) that you need to get the difference of, and don't feel like putting it into a variable:

{string.Format("{0}:{1}:{2}", 
                (int) DateDiff(Date2,Date1).TotalHours, 
                 DateDiff(Date2,Date1).Minutes,
                 DateDiff(Date2,Date1).Seconds)}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top