0

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.

2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by razree
0

Have a look at THIS webpage.

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

Edited by Mike Askew: Added explanation

0

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())
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.