title: How to calculate day between two dates?
body: <p>I have 2 textboxes, txtStartDate.Text and txtEndDate.Text, user choose date through calendar date picker. 
  Now I want to count the days between the two selected date and save the result in the database field totalDay(type integer), the following is my code:</p>
  
  <p>But when I click button and try to save it into database, i receive this error:</p>
  
  <p>The version of SQL Server in use does not support datatype 'time'. </p>
  
  <p>What should I do to overcome this problem?</p>
  
  <pre><code>Imports System
  Imports System.Data
  Imports System.Data.SqlClient
  Imports System.Threading
  Imports System.Globalization
  
  Partial Class addevent
  Inherits System.Web.UI.Page
  
  Protected Sub ButtonAddEvent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddEvent.Click
  
      Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
      '"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\eventdb.mdf;Integrated Security=True;User Instance=True"
      Dim con As SqlConnection = New SqlConnection(connString)
  
      Dim cmdQuery As String = "INSERT INTO eventinfo(venue,totalDay,eventTitle,startDate,endDate,description) VALUES (@venue,@totalDay,@eventTitle,@startDate,@endDate,@description)"
      Dim cmd = New SqlCommand(cmdQuery)
      cmd.Connection = con
      cmd.CommandType = CommandType.Text
      con.Open()
      cmd.Parameters.AddWithValue("@eventTitle", txtEventTitle.Text)
      cmd.Parameters.AddWithValue("@venue", txtEventLocation.Text)
      cmd.Parameters.AddWithValue("@startDate", txtStartDate.Text)
      cmd.Parameters.AddWithValue("@endDate", txtEndDate.Text)
      cmd.Parameters.AddWithValue("@description", txtEventDescription.Text)
  
      Dim fmt As String = "dd/MM/yyyy"
      Dim dtStart As DateTime = DateTime.ParseExact(txtStartDate.Text, fmt, Nothing)
      Dim dtEnd As DateTime = DateTime.ParseExact(txtEndDate.Text, fmt, Nothing)
  
      Dim ts As TimeSpan = dtEnd - dtStart
  
      cmd.Parameters.AddWithValue("@totalDay", ts.TotalDays)
  
  
      cmd.ExecuteNonQuery()
      cmd.Parameters.Clear()
      con.Close()
  
      Response.Redirect("~/addbooth.aspx")
  
  End Sub
  End Class
  </code></pre>
  
  <p>My table structure:
  <img src="https://i.stack.imgur.com/8m5TZ.jpg" alt="enter image description here"></p>