timespan

How do I calculate relative time?

Given a specific DateTime value, how do I display relative time, like 2 hours ago 3 days ago a month ago etc, etc...? ...

[C#] Parse string to TimeSpan

I have some strings of xxh:yym format where xx is hours and yy is minutes like "05h:30m". What is an elegant way to convert a string of this type to TimeSpan? ...

How to Convert ISO 8601 Duration to TimeSpan in VB.Net?

Is there a standard library method that converts a string that has duration in the standard ISO 8601 Duration (also used in XSD for its duration type) format into the .NET TimeSpan object? For example, P0DT1H0M0S which represents a duration of one hour, is converted into New TimeSpan(0,1,0,0,0). A Reverse converter does exist which wor...

Handling and storing elapsed time

I'm having problems deciding on what is the best way is to handle and store time measurements. I have an app that has a textbox that allows the users to input time in either hh:mm:ss or mm:ss format. So I was planning on parsing this string, tokenizing it on the colons and creating TimeSpan (or using TimeSpan.Parse() and just adding a...

How can I just get the "Year" portion from the output of timespan() in CodeIgniter?

I have a Date of Birth field and trying to use the timespan function to get the age, but returns "28 Years, 2 Months, 2 Weeks, 3 Days, 15 Hours, 16 Minutes". Any idea how I can just get the "28 Years" part? Thanks! ...

ActionScript 3.0 + Calculate timespan between two dates?

In ActionScript 3.0, is there an automatic way to calculate the number of days, hours, minutes and seconds between two specified dates? Basicly, what I need is the ActionScript equivalent of the .NET Timespan class. Any idea? ...

Environment.TickCount vs DateTime.Now

Is it ever OK to use Environment.TickCount to calculate time spans? int start = Environment.TickCount; // Do stuff int duration = Environment.TickCount - start; Console.WriteLine("That took " + duration " ms"); Because TickCount is signed and will rollover after 25 days (it takes 50 days to hit all 32 bits, but you have to scrap the s...

NUnit test DateTime without .Net Timespan or DateTime function

What is the c# optimised version of the following, without using .Net's Timespan or DateTime. How would I NUnit test it? TimeSpan ts = Date1 - Date2; int numberOfDays = ts.Days; ...

Can you round a .NET TimeSpan object?

Can you round a .NET TimeSpan object? I have a Timespan value of: 00:00:00.6193789 Is there a simple way to keep it a TimeSpan object but round it to something like 00:00:00.61 ? ...

Pet projects

Most of us has one, how long have you been working on your pet project? ...

C# How do I convert ticks to minutes?

I have a ticks value of 28000000000 which should be 480 minutes but how can I be sure? How do I convert a ticks value to minutes? Thanks ...

Weekly Schedules - How can you store this in a database?

Currently, I'm working on a project to manage maintenance windows on a database of servers, etc. Basically, I only need to be accurate down to the hour, but allow for them to be set to allow, or disallow, for each day of the week. I've had a few ideas on how to do this, but since I work by myself, I'm not wanting to commit to anything w...

Java equivalent to C#'s TimeSpan

Does Java have a data type that represents a period of time eg 34 seconds, 5 minutes etc. I've seen a few implementations of a TimeSpan that cover a Time period like from the 10th of December to the 11th of December. What I need is something like TimeSpan in C#. ...

T-SQL check constraint for .NET TimeSpan?

I have a nvarchar(max) column in a sql server 2005 table which is used for storing string representations of .NET TimeSpan objects. Sometimes the table is manually edited. I want to add a check constraint to verify that the string can be parsed by TimeSpan.Parse(). How should I do this? I guess I could use one of the methods for enabling...

Time/Date range grammars

I need to parse strings containing time spans such as: Thursday 6:30-7:30 AM December 30, 2009 - January 1, 2010 1/15/09, 7:30 to 8:30 PM Thursday, from 6:30 to 7:30 AM and others... added 6:30 to 7:30 and date/times such as most any cases that Word's insert->date can generate As I'd be extremely surprised if anything out there ...

Winforms &TimeSpan - Which control works best ?

I am building a form with winforms - and should add a view and editable time span value. Which controls works best for this ? A normal edit control shows the value correctly -> but it's not really nice for changing values the normal date time picker doesn't work the masked edit control doesn't have got any standard mask for this Doe...

How to Convert Datareader Result of DbType.Time to Timespan Object ?

I am reading a result from a MS SQL 2008 Database with a column type of dbtype.time from a datareader, using c# with DAAB 4.0 framework. My problem is the MSDN docs say dbtype.time should map to a timespan but the only close constructor for timespan I see accepts a long, and the result returned from the datareader cannot be cast to a lo...

SSRS: Summing TimeSpan values in a report

I have a report and a datasource where one of the columns are of type TimeSpan. The TimeSpan value appears to display correctly in the report when I use Fields!TheTime.Value, no problem there. 07:02:00 05:41:00 But I would like to do a Sum on those values to get the total time of a group. In C# and such I can of course do a TimeSpan ...

Linq to sql, summing timespan?

I have a time field in a mssql 2008 database that I want to do something to the effect of: Timespent = x.sum(x => x.AmountOfTime); Where AmountOfTime is a time MSSQL field. Sum seems to only work on decimals, how can I add these columns? ...

TimeSpan.FromSeconds(-1.0) and double.NaN

We are building a WPF app and are seeing some random and very strange behavior which seems to originate from within the BCL. We are catching an unhandled exception with the following stacktrace: [ArgumentException], "TimeSpan does not accept floating point Not-a-Number values." at System.TimeSpan.Interval(Double value, Int32 scale) ...