none
Get Difference Between 2 Dates RRS feed

Answers

  • You can use TimeSpan class.

    Code Snippet

    System.DateTime dtOne = DateTime.Today;
    System.DateTime dtTwo = DateTime.Today.AddHours(10);

    System.TimeSpan diffResult = dtTwo.Subtract(dtOne);
    MessageBox.Show(diffResult.Hours.ToString());


    Hope this helps.
    Thursday, January 31, 2008 10:13 AM

All replies

  • You can use TimeSpan class.

    Code Snippet

    System.DateTime dtOne = DateTime.Today;
    System.DateTime dtTwo = DateTime.Today.AddHours(10);

    System.TimeSpan diffResult = dtTwo.Subtract(dtOne);
    MessageBox.Show(diffResult.Hours.ToString());


    Hope this helps.
    Thursday, January 31, 2008 10:13 AM
  • Hi obrienkev,

     

    Try this code

     

    TimeSpan i = DateTime.Now - DateTime.Parse("20-Jan-2008");

    Console.WriteLine(i.TotalHours.ToString());

    Console.ReadLine();

     

    Hope it helps,

    SATYA

     

    Thursday, January 31, 2008 11:00 AM