Calculating time

  • Thread starter Thread starter Philip Townsend
  • Start date Start date
P

Philip Townsend

I need to add together some times that are stored in a database as
seperate int values. Here is a code segment that is flawed (ts is
declared as: TimeSpan ts=new TimeSpan(0,0,0). As is, the value of ts
remains at 0:00:00. Can anybody help with this?

h=dr.GetInt32(dr.GetOrdinal("hours"));
m=dr.GetInt32(dr.GetOrdinal("minutes"));
s=dr.GetInt32(dr.GetOrdinal("seconds"));
TimeSpan tempTS=new TimeSpan(h,m,s);
ts.Add(tempTS);

thnx!
 
So you have an initial time, to which you need to add another value - am I
getting it right?
 
ts.Add does not modify the TimeStamp (TimeStamps are immutable), it returns
a new TimeStamp. So, you have to write:

ts = ts.Add(tempTS);

Bruno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top