title: How to store Date and Time input type from html form into sqlite3 DB
body: <p>I am setting up a <code>reminder</code> feature in a personal assistant application. The application accepts the details of the reminder as a html form which also include <code>date</code> and <code>time</code> input fields.</p>
  
  <p>I am using golang for creating my server and created a sqlite database using it. But the value of date and time from the form doesn't get saved in the DB while other fields like title, description, etc gets saved. What datatype should I use for my time and date fields in the sqlite DB?</p>
  
  <p>I have tried using <code>TEXT</code> as the datatype for date and time but it doesn't work.</p>
  
  <p>Input form:</p>
  
  <pre><code>   ...
  &lt;div class="form-group"&gt;
     &lt;label for="date"&gt;Date&lt;/label&gt;
     &lt;input type="date" class="form-control" id="date" data-ng-model="formData.remDate" required&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
     &lt;label for="time"&gt;Time&lt;/label&gt;
     &lt;input type="time" class="form-control" id="time" data-ng-model="formData.remTime" required&gt;
  &lt;/div&gt;
     ...
  </code></pre>
  
  <p>This is the <code>reminder object</code> that is generated from the form:</p>
  
  <pre><code>{title: "learn golang", description: "How do I save date and time in database?", date: Mon Apr 08 2019 00:00:00 GMT+0530 (India Standard Time), time: Thu Jan 01 1970 20:00:00 GMT+0530 (India Standard Time)}
  </code></pre>
  
  <p>Golang file for creating and storing in DB:</p>
  
  <pre><code>package controllers
  
  import (
      "net/http"
      "database/sql"
      "fmt"
      "strconv"
  
      _ "github.com/mattn/go-sqlite3"
  )
  
  type reminder struct {
      id int
      title string
      description string
      date string
      time string
  }
  
  func ReminderController(w http.ResponseWriter, r *http.Request) {
  
      w.Header().Set("Access-Control-Allow-Origin", "*")
      w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
      r.ParseForm()
  
      request := reminder{
          title: r.FormValue("title"),
          description: r.FormValue("description"),
          date: r.FormValue("date"),
          time: r.FormValue("time"),
      }
      fmt.Println(request)
  
      AddReminder(request, w)
  
  }
  
  func prepareDB() {
      database, err := sql.Open("sqlite3", "./jarvis.db")
      checkErr(err)
  
      statement, err := database.Prepare("CREATE TABLE IF NOT EXISTS reminder (id INTEGER PRIMARY KEY, title TEXT, description TEXT, date TEXT, time TEXT")
      checkErr(err)
  
      statement.Exec()
  }
  
  func AddReminder(reminderObject reminder,  res http.ResponseWriter) {
      prepareDB()
  
      database, err := sql.Open("sqlite3", "./jarvis.db")
      checkErr(err)
  
      statement, err := database.Prepare("INSERT INTO reminder (title, description, date, time) VALUES (?,?,?,?) ")
      checkErr(err)
      fmt.Println(reminderObject.title)
      statement.Exec(reminderObject.title, reminderObject.description, reminderObject.date, reminderObject.time)
  
      ShowReminder()
  
      res.Write([]byte(`{"status": "success", "message": "Reminder has been set !"}`))
  }
  
  func ShowReminder() {
      prepareDB()
  
      database, err := sql.Open("sqlite3", "./jarvis.db")
      checkErr(err)
  
      rows, err := database.Query("SELECT id, title, description, date, time FROM reminder")
      checkErr(err)
  
      var id int
      var title string
      var description string
      var date string
      var time string
  
      for rows.Next() {
          rows.Scan(&amp;id, &amp;title, &amp;description, &amp;date, &amp;time)
          fmt.Println(strconv.Itoa(id) + ": " + title + " " + description + "\nEnd Time : " + date + ":" + time)
      }
  }
  
  func checkErr(err error) {
      if err != nil {
          panic(err)
      }
  }
  </code></pre>
  
  <p>Output generated in go console :</p>
  
  <pre><code>3: learn golang How do I save date and time in database?
  End Time : :
  </code></pre>