how to get time difference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jassim Rahma

    how to get time difference

    I have the following dates:

    17:03:2008 21:15:58
    19:47:2008 13:07:07


    and i want to get the time difference between the two dates in the
    following formats:

    1. int format, for example: 9,253 minutes
    2. hh:mm format, for example: 18:17 or even 218:17


    Many Thanks,
    Jassim Rahma

    *** Sent via Developersdex http://www.developersdex.com ***
  • Marc Gravell

    #2
    Re: how to get time difference

    ?? 19:47:2008 ??

    Something like below perhaps:

    DateTime dt1 = DateTime.Parse( "17/03/2008 21:15:58"),
    dt2 = DateTime.Parse( "19/07/2008 13:07:07");

    TimeSpan delta = dt2 - dt1;

    string foo = ((int)Math.Floo r(delta.TotalMi nutes)).ToStrin g(),
    bar = string.Format(" {0}:{1}",
    (int)Math.Floor (delta.TotalHou rs), delta.Minutes);

    Marc

    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: how to get time difference

      Marc Gravell wrote:
      Something like below perhaps:
      >
      DateTime dt1 = DateTime.Parse( "17/03/2008 21:15:58"),
      dt2 = DateTime.Parse( "19/07/2008 13:07:07");
      >
      TimeSpan delta = dt2 - dt1;
      >
      string foo = ((int)Math.Floo r(delta.TotalMi nutes)).ToStrin g(),
      bar = string.Format(" {0}:{1}",
      (int)Math.Floor (delta.TotalHou rs), delta.Minutes);
      I would drop the Math.Floor and use {1,00} ...

      Arne

      Comment

      • Marc Gravell

        #4
        Re: how to get time difference

        I would drop the Math.Floor

        Fair enough - I'm just too lazy to remember all the different rounding
        rules; by making it explicit it means I don't have to think to often ;-
        p

        (especially when re-visiting an old bit of code)

        Marc

        Comment

        Working...