none
Time difference RRS feed

  • Question

  • hi

    I want to find a time difference between two DateTimePicker with same formate

    my error try

     Try
                Dim HRS As TimeSpan
                Dim St As TimeSpan = TimeSpan.Parse(DATETIM_COM.Value.ToLongTimeString)
                Dim Cl As TimeSpan = TimeSpan.Parse(DATETIM_COMK.Value.ToLongTimeString)
    
                HRS = Cl - St
                MsgBox(HRS)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

    messag

    Thursday, March 7, 2019 7:51 PM

Answers

  • Hi

    Does this work:

    comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", CInt(DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value)))


    Regards Les, Livingston, Scotland

    • Marked as answer by ahmeddc Friday, March 8, 2019 2:06 AM
    Friday, March 8, 2019 12:55 AM

All replies

  • Just subtract, then format.

            Dim ts As TimeSpan
            ts = DateTimePicker2.Value - DateTimePicker1.Value
    
            Dim s As String
            s = ts.ToString("d\.hh\:mm\:ss\.fff")
    


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Thursday, March 7, 2019 8:29 PM
  • Hi

    I think this is what you need - maybe, perhaps possibly:

      Private Sub DATETIM_COM_ValueChanged(sender As Object, e As EventArgs) Handles DATETIM_COM.ValueChanged, DATETIM_COMK.ValueChanged
        Label1.Text = DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value).ToString
      End Sub

    OR maybe:

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MessageBox.Show("HRS = " & DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value).ToString)
      End Sub


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, March 7, 2019 8:34 PM
    Thursday, March 7, 2019 8:31 PM
  • Hi

    I think this is what you need - maybe, perhaps possibly:

      Private Sub DATETIM_COM_ValueChanged(sender As Object, e As EventArgs) Handles DATETIM_COM.ValueChanged, DATETIM_COMK.ValueChanged
        Label1.Text = DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value).ToString
      End Sub

    OR maybe:

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MessageBox.Show("HRS = " & DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value).ToString)
      End Sub


    Regards Les, Livingston, Scotland


    thanks

    I used this method and found the difference
    But the problem now is not insert the difference correctly in the database

       Dim checkIn As DateTime = DateTime.Parse(FEMPLOYPGAPSCOMUPDAT.DATETIM_COM.Value)
                Dim checkOut As DateTime = DateTime.Parse(FEMPLOYPGAPSCOMUPDAT.DATETIM_COMK.Value)
                Dim timeDiff As TimeSpan = checkOut.Subtract(checkIn)
    
                comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", timeDiff) '

    When I add time in this way, I do it successfully

    comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", FEMPLOYPGAPSCOMUPDAT.DATETIM_COMK.Value.ToLongTimeString)
    access column type (EMPLOYEDATE_DATECANCELCOM) in table  long time


    • Edited by ahmeddc Thursday, March 7, 2019 9:09 PM
    Thursday, March 7, 2019 8:46 PM
  • thanks dbasnett
    Thursday, March 7, 2019 8:46 PM
  • Hi

    What exactly do you want? You talk about a calculated time difference between two dates and then, you want to store it as a LongTime.

    A calculated time difference is not an instant, it is a period of time. Perhaps you need to store it as a Long value such as Hours.


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, March 7, 2019 9:57 PM
    Thursday, March 7, 2019 9:56 PM
  • Hi

    What exactly do you want? You talk about a calculated time difference between two dates and then, you want to store it as a LongTime.

    A calculated time difference is not an instant, it is a period of time. Perhaps you need to store it as a Long value such as Hours.


    Regards Les, Livingston, Scotland



    You modify the method and the value appears -1 in column in database

     Dim hours As Single = DateDiff(DateInterval.Minute, DateTime.Parse(FEMPLOYPGAPSCOMUPDAT.DATETIM_COMK.Value), DateTime.Parse(FEMPLOYPGAPSCOMUPDAT.DATETIM_COM.Value))
                comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", Int32.Parse(hours))

    Friday, March 8, 2019 12:36 AM
  • Hi

    Does this work:

    comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", CInt(DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value)))


    Regards Les, Livingston, Scotland

    • Marked as answer by ahmeddc Friday, March 8, 2019 2:06 AM
    Friday, March 8, 2019 12:55 AM
  • Hi

    Does this work:

    comb.Parameters.AddWithValue("@EMPLOYEDATE_DATECANCELCOM", CInt(DateDiff(DateInterval.Hour, DATETIM_COM.Value, DATETIM_COMK.Value)))


    Regards Les, Livingston, Scotland

    thanks


    Friday, March 8, 2019 2:06 AM