none
Looking for a function which manage two dates RRS feed

  • Question

  • Hi all of you, primary platform is Framework 2.0 (Vb)

    I got a date from a DateTimePicker control and then a date value from a system.time.now value, i.e:

    Dim fechafinal As DateTime = CType(Me.txtFechaInicioOR.Text, Date)

    Dim fecha3 As TimeSpan = fechafinal.Subtract(CType(Me.dtpFechaSalidaOR.Text, Date))

    The first value equals "16/05/2012 20:57:05"

    The second one equals "System.Windows.Forms.DateTimePicker, Value: 18/05/2012 21:04:17"

    I can’t work out, I would like to get

    Fecha3.days = 2

    Fecha3.hours = n

    And so on and forth

    Thanks indeed for your help


    Enric

    Wednesday, May 16, 2012 7:08 PM

Answers

  • Eric

    If you want to handle date times than know what you want, 

    Between 1999 and 2000 was at a certain moment the difference

    A nanosecond, a millisecond a second, a minute, an hour, a day, a week, a month, a year, a century, a millenium

    If you want to check from that the differences you have to subtract that kind of quantities

    You can do that using the constructor and creating a comparable date in your case in VB

    dim myFirstDate = CDate(TextBox1.tex)

    Dim MyComparableFirstDate as new DateTime(myFirstDate.year, myFirsdate.month, myFirstdate.day, myFirstDate.Hour)



    The same for your second but now you can direct take the value from your datetimepicer as that is a DateTime Type


    Success
    Cor

    • Marked as answer by Enric Vives Thursday, May 17, 2012 7:48 AM
    Thursday, May 17, 2012 5:17 AM

All replies

  • I am amazed, I have changed my code for this one and I get positive values but all of them are incorrect:

    Dim fechafinal As Date = CType(Me.txtFechaInicioOR.Text, Date)
    Dim fecha3 As TimeSpan = CType(Me.dtpFechaSalidaOR.Text, Date).Subtract(fechafinal)
    fecha3.days = 1 ????? instead of 2

    The first value equals "16/05/2012 20:57:05"

    The second one equals "System.Windows.Forms.DateTimePicker, Value: 18/05/2012 21:04:17"


    Enric

    Wednesday, May 16, 2012 7:17 PM
  • Eric

    If you want to handle date times than know what you want, 

    Between 1999 and 2000 was at a certain moment the difference

    A nanosecond, a millisecond a second, a minute, an hour, a day, a week, a month, a year, a century, a millenium

    If you want to check from that the differences you have to subtract that kind of quantities

    You can do that using the constructor and creating a comparable date in your case in VB

    dim myFirstDate = CDate(TextBox1.tex)

    Dim MyComparableFirstDate as new DateTime(myFirstDate.year, myFirsdate.month, myFirstdate.day, myFirstDate.Hour)



    The same for your second but now you can direct take the value from your datetimepicer as that is a DateTime Type


    Success
    Cor

    • Marked as answer by Enric Vives Thursday, May 17, 2012 7:48 AM
    Thursday, May 17, 2012 5:17 AM