TimeSpan object question

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

    #1

    TimeSpan object question

    I haven't worked with the TimeSpan object before. So bare with me if
    this seems like a newb question. But if I wanted to know how many
    days from the current date until 2/4/2008. I have written this much
    code so far.

    DateTime startDate = new DateTime("2008-02-04");
    DateTime curDate = DateTime.Now();
    TimeSpan ts = startDate.Subtr act(curDate);

    Now I get lost. I was expecting to find a Days property off of the
    TimeSpan object. No such luck. Where am I going wrong?

    Thanks,
    Kelly Greer
    kellygreer1@nos pan.com
    change nospam to yahoo
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: TimeSpan object question

    Kelly,

    The Days property should be accessible through the ts variable. It's
    definitely there. What makes you think it is not?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "kellygreer 1" <kellygreer1@ya hoo.comwrote in message
    news:bd743be8-6607-45ca-a515-553fd276a957@d2 1g2000prf.googl egroups.com...
    >I haven't worked with the TimeSpan object before. So bare with me if
    this seems like a newb question. But if I wanted to know how many
    days from the current date until 2/4/2008. I have written this much
    code so far.
    >
    DateTime startDate = new DateTime("2008-02-04");
    DateTime curDate = DateTime.Now();
    TimeSpan ts = startDate.Subtr act(curDate);
    >
    Now I get lost. I was expecting to find a Days property off of the
    TimeSpan object. No such luck. Where am I going wrong?
    >
    Thanks,
    Kelly Greer
    kellygreer1@nos pan.com
    change nospam to yahoo

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: TimeSpan object question

      Hi,



      "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
      news:MPG.220192 dee0909e07ea@ms news.microsoft. com...
      kellygreer1 <kellygreer1@ya hoo.comwrote:
      >Now I get lost. I was expecting to find a Days property off of the
      >TimeSpan object. No such luck. Where am I going wrong?
      >
      I'm not sure - TimeSpan definitely does have a Days property, and
      always has had. What happens when you try to use ts.Days?
      I believe that the correct property is TimeSpan.TotalD ays
      --
      Ignacio Machin
      The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

      Mobile & warehouse Solutions.


      Comment

      • Peter Duniho

        #4
        Re: TimeSpan object question

        On Wed, 23 Jan 2008 10:32:29 -0800, Ignacio Machin ( .NET/ C# MVP )
        <machin TA <"laceupsolutio ns.com>"wrote:
        >I'm not sure - TimeSpan definitely does have a Days property, and
        >always has had. What happens when you try to use ts.Days?
        >
        I believe that the correct property is TimeSpan.TotalD ays
        It depends on what the OP wants. If they just want the integral days
        portion of the TimeSpan, Days is correct.

        Comment

        • kellygreer1

          #5
          Re: TimeSpan object question

          On Jan 23, 1:41 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
          wrote:
          On Wed, 23 Jan 2008 10:32:29 -0800, Ignacio Machin ( .NET/ C# MVP )
          >
          <machin TA <"laceupsolutio ns.com>"wrote:
          I'm not sure - TimeSpan definitely does have a Days property, and
          always has had. What happens when you try to use ts.Days?
          >
          I believe that the correct property is TimeSpan.TotalD ays
          >
          It depends on what the OP wants. If they just want the integral days
          portion of the TimeSpan, Days is correct.
          What I ended up doing was taking A ticks minus B ticks ... and then
          dividing by the TimeSpan.TicksP erDay.
          I'll fix this up tomorrow.

          Wait. I just figured it out. Guess I was struck stupid today. I was
          looking at the static side of TimeSpan and not an instance of
          TimeSpan. Subtract 10 cool points. lol

          Thanks guys,
          Kelly

          Comment

          Working...