Calculating days from dates

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

    #1

    Calculating days from dates

    Hi

    How can I calculate days from the two dates entered in date time picker
    fields on winform by a user?

    Thanks

    Regards




  • Cor Ligthert[MVP]

    #2
    Re: Calculating days from dates

    John,

    You first have to define what is a day.

    For some people is it just two dates, (which means that a millisecond is one
    day), for others it is at the second exact.

    Cor


    "John" <info@nospam.in fovis.co.ukschr eef in bericht
    news:OK1fhIYIJH A.2256@TK2MSFTN GP06.phx.gbl...
    Hi
    >
    How can I calculate days from the two dates entered in date time picker
    fields on winform by a user?
    >
    Thanks
    >
    Regards
    >
    >
    >
    >

    Comment

    • Family Tree Mike

      #3
      Re: Calculating days from dates

      You should use DateTime.Subtra ct to get a timespan, and then totaldays, as
      in this example:

      Module Module1

      Sub Main()
      Dim dt1 As New DateTime(2008, 9, 11)
      Dim dt2 As New DateTime(2008, 9, 15)

      Console.Out.Wri teLine("Days: " & dt2.Subtract(dt 1).TotalDays())
      Console.In.Read Line()
      End Sub

      End Module


      "John" <info@nospam.in fovis.co.ukwrot e in message
      news:OK1fhIYIJH A.2256@TK2MSFTN GP06.phx.gbl...
      Hi
      >
      How can I calculate days from the two dates entered in date time picker
      fields on winform by a user?
      >
      Thanks
      >
      Regards
      >
      >
      >
      >

      Comment

      • kimiraikkonen

        #4
        Re: Calculating days from dates

        On Sep 28, 6:51 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
        Hi
        >
        How can I calculate days from the two dates entered in date time picker
        fields on winform by a user?
        >
        Thanks
        >
        Regards
        Assuming you have 2 DateTimePicker controls, you can use substract
        method to get result as string:

        'Calculate DateTimePicker1 - DateTimePicker2
        '-----Begin-----
        Dim str As String
        str = DateTimePicker1 .Value.Date.Sub tract _
        (DateTimePicker 2.Value.Date).D ays.ToString()
        'Show difference in message box
        MsgBox(str)
        '-----End------

        Hope this helps,

        Onur Güzel

        Comment

        Working...