Hi all
I want to be able to calculate the difference between two dates, written in SQL db. The difference must be in days/hours format. This is my code:

Dim SQLConn As New SqlConnection()
        Dim SQLCmd As New SqlCommand()
        Dim dr As SqlDataReader
		
		Dim arrival As Date
        Dim departure As Date
		
        SQLConn.ConnectionString = ConnString
        SQLConn.Open()

        SQLCmd.Connection = SQLConn
        SQLCmd.CommandText = sqlstr
        dr = SQLCmd.ExecuteReader
         
		While dr.Read()
		arrival= dr.Item("ODHOD")
        departure = dr.Item("PRIHOD")
	    End While

        SQLConn.Close()

I've read timespan is one of the options to use for this case but don't know exactly how to do it..?
Any help would be appreciated.

Have a look at THIS webpage.

Can apply the same technique of date/time measurement possibly? Not entirely sure though.

Hi
I decided it's probably easyer for me to work a way arroun. I have calculated dates from datetimepickers on another form, write diff to base and on another form just got this data out.
I used this code:

Dim odhod As Date = DateTimePicker1.Value

        Dim prihod As Date = DateTimePicker2.Value
        Dim razlika As TimeSpan
        razlika = prihod.Subtract(odhod)

        'MessageBox.Show(razlika.Days.ToString() & "/" & razlika.Hours.ToString())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.