timespan

TimeSpan to Localized String in C#

Is there an easy way (maybe built in solution) to convert TimeSpan to localized string? For example new TimeSpan(3, 5, 0); would be converted to 3 hours, 5minutes (just in polish language). I can of course create my own extension: public static string ConvertToReadable(this TimeSpan timeSpan) { int hours = timeSpan.Hours; ...

Timespan in C# converting to int? Somehow?

I'm trying to use the Timespan class to create a start time and a stop time, get the difference and ultimately dividing and multiplying the result against another number. The problem is getting into something I can work with. Any suggestions? ...

MessageBox.Show(TimeSpan)

i would like to show a TimeSpan in a MessageBox but am getting an error: DateTime date1 = new DateTime(byear, bmonth, bday, 0, 0, 0); DateTime datenow = DateTime.Now; TimeSpan age = datenow - date1; MessageBox.Show(ToString(age)); Error 1 No overload for method 'ToString' takes '1' arguments how do i output a messagebox with Ti...

time calculation within LINQ

Hi I want a linq query to return a calculated timespan, i have used the timespan function before, but im not sure how to incorporate it into linq. Basically the linq is returning a datetime field which i want to subtract from the current datetime to get days and hours. Any help appreciated! Thanks ...

Looping through the days of the week inside of C# TimeSpan Class

Hi, I'm trying to loop through EACH DAYof the WEEK between 2 time periods DateTime start = new DateTime(2010, 1, 1); DateTime end = new DateTime(2011, 12, 12); I have managed to get the number of days between these dates using the following code TimeSpan range = (end - start); turn out to be 710. I am now looking to get ...

How to best implement IPropertyChanged on Timespan subtype?

in .NET (and WPF), I need to monitor changes on a Timespan object which doesn't include any change event like PropertyChanged. What would be the best way to add this functionnality? ...

How to deal with Rounding-off TimeSpan?

I take the difference between two DateTime fields, and store it in a TimeSpan variable, Now I have to round-off the TimeSpan by the following rules: if the minutes in TimeSpan is less than 30 then Minutes and Seconds must be set to zero, if the minutes in TimeSpan is equal to or greater than 30 then hours must be incremented by 1 and Mi...

Can I Do a Foreach on a TimeSpan by Timespan Type?

I have a requirement that regardless of the start and dates that I need to loop through that timespan and calculate figures at the month level. I cannot seem to figure it out, and maybe it is not possible, but I would like to do something like: FOREACH Month As TimeSpan in ContractRange.Months Do Calculations (Month.Start, Month.End)...

How to parse string with hours greater than 24 to TimeSpan?

How to parse string like 30:15 to TimeSpan in C#? 30:15 means 30 hours and 15 minutes. string span = "30:15"; TimeSpan ts = TimeSpan.FromHours(Convert.ToDouble(span.Split(':')[0])).Add(TimeSpan.FromMinutes(Convert.ToDouble((span.Split(':')[1])))); This does not seem too elegant. ...

Adding a TimeSpan to a given DateTime

I just want to add 1 day to a DateTime. So I wrote: DateTime date = new DateTime(2010, 4, 29, 10, 25, 00); TimeSpan t = new TimeSpan(1, 0, 0, 0); date.Add(t); Console.WriteLine("A day after the day: " + date.ToString()); I tought the result would be: 2010 04 30- 10:25:00 but I'm still getting the initial date. What's wrong? ...

Finding 'free' times in MySQL

Hi, I've got a table as follows: mysql> DESCRIBE student_lectures; +------------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL |...

Confusing of TTimeSpan usage in Delphi 2010

Hi All, I tried the new Record type TTimeSpan in Delphi 2010. But I encourage a very strange problem. assert(TTimeSpan.FromMilliseconds(5000).Milliseconds = 5000); This assertion does not pass. The value of 'TTimeSpan.FromMilliseconds(5000).Milliseconds' is expected to be 5000, but it was 0. I dig deeper: function TTimeSpan.GetMil...

Briefest way to display TimeSpan value as an elapsed time e.g. 1:45:33

I'd like an easy way to display any TimeSpan as an elapsed time without using loops or custom logic e.g. hours : minutes : seconds I'm sure there must be a .NET built-in or format string that applies, however I'm unable to locate it. ...

Why 10675199.02:48:05.4775807 TimeSpan Maximum for CompilationSection?

I was looking at the metadata for System.Web.Configuration.CompilationSection, and noticed the following attribute on the TimeSpan BatchTimeout property: [TimeSpanValidator(MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")] Could someone explain why this is the allowed max value? TimeSpan itself has an upper...

Label displaying Timespan disappearing in XP but not in newer Windows versions

I have a stopwatch timer that I've added to my program. It's working fine on my Win 7 machine, and on the Vista machines I've tried, but in XP, the hrs and mins zeros disappear when the timer starts, but will come back if I reset the timer. Here's all of my code that I have for the timer. I've removed everything that didn't seem necess...

How to determine the time span on map ?

How could I determine the time needed to go from one location to another ? Is there any map API (web services, servlets) that allows this ? ...

SQL Server 2008 Time column messing up GridView DataFormatString

I've got a nullable column in SQL Server 2008 that I use to store a time. When I use LINQ to SQL and pull data back it comes back as TimeSpan?. When I bind that to a GridView and try to format it using DataFormatString="{0:t}" it still shows the seconds. Any thoughts? ...

C# TimeSpan and total hours

Hi, i want to subtract two dates and get the total hours of the TimeSpan object that it's returned. For example, if the TimeSpan is of 2 days, the total hours are 48. Thanks ...

Calculating timespans in Javascript/ECMAScript

I've got a variable that holds a number of miliseconds which represents the timespan from now to a specified point in the future. I want to convert this milisecond figure into a timespan value I can display to users. I know I can do this the native way with modulo arithmetic and manually displaying the result to the user, but I want to...

mysql test if time is within a time span over midnight

I am working on a mysql query that will search a database of entries that each have a time span to see if a user input time or time span falls within the entries spans. Ex user can input "13:00" or "13:00-16:00" the database has entries like so: id startTime endTime 1 08:00 12:00 2 20:00 03:00 3 1...