Solved

# Difference in seconds between  two datetimes, C# asp.net webpage

Posted on 2007-07-24
606 Views
I am trying to calculate the seconds between two date times in Asp.net with C# as the language for a webpage I am developing. My goal is to calculate a datetime I have marked as "indt"(an earlier datetime) and the current time which i have marked as "inct". How do you go about getting this value in seconds as an Integer.
Exampe
inct-indt= x seconds
If any other information is needed just ask.
0
Question by:tomcalef

LVL 22

Accepted Solution

TimeSpan ts = inct - indt;
MessageBox.Show(ts.TotalSeconds.ToString());
0

LVL 7

Expert Comment

int seconds = (int)(inct-indt).Seconds;
0

LVL 8

Expert Comment

DateTime date = DateTime.Now;
DateTime dte = DateTime.Now.AddDays(1);
TimeSpan span =  dte.m- date;
int s = span.Milliseconds;
0

LVL 7

Expert Comment

int seconds = (int)Math.Round((inct-indt).TotalSeconds);
0

Author Comment

I would have split the points if it wasnt for the first answer working perferct, Thanks alot guys.
0

## Join & Write a Comment Already a member? Login.

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

#### 745 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!