Question

So I have a webapp that calls a SQL package function that returns a number type in the form of d.(fraction of a day[up to two decimal places]).

So for example, 1.5 would translate to one and a half days.

I want to convert it to a timespan. From working with C#, there seems to be a fair amount of useful library functions, so I was hoping there might be some function I could call and do the conversion in a line or two. However, the closest thing I could find was Parse. However it only has an hour format of 0-23 hours rather than something that takes in fractions of days.

So is there some other function I could use or could I use some sort of hackery like this:

culture = new CultureInfo("d.(hh*24)"), 
TimeSpan ts = TimeSpan.Parse(value, culture);
Était-ce utile?

La solution

Try this:

TimeSpan ts = TimeSpan.FromDays(value);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top