Skip to content

How to calculate the time difference between two date fields

July 26, 2012

So the London 2012 Olympics is about to start, and I have been busy refining the web application in regards to the session data holding the session time periods, and one of the things I had to improve on in the C# code is to calculate the time differences between two date fields StartTime and EndTime in the database.

Using NHibernate, I had written a piece of code in C# to calculate the two fields where session is the IList<Session> which gives a list of sessions back from the Session table.

TimeSpan span;

if (session.EndTime != null)
span = ((DateTime)session.EndTime).Subtract((DateTime)session.StartTime);
span = TimeSpan.Zero;

You can use this on the RDLC reporting, and embed this into the Datatable and replace sessionlength with the code above.

There you go, something related to the Olympics with timing!


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: