Difference in seconds between  two datetimes, C# webpage

Posted on 2007-07-24
Last Modified: 2008-01-09
I am trying to calculate the seconds between two date times in 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.
    inct-indt= x seconds
If any other information is needed just ask.
Question by:tomcalef
    LVL 22

    Accepted Solution

    TimeSpan ts = inct - indt;
    LVL 7

    Expert Comment

    int seconds = (int)(inct-indt).Seconds;
    LVL 8

    Expert Comment

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

    Expert Comment

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

    Author Comment

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    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.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now