Store date in SQLite
<p>There is a lot of discussion here, but what I have tried isn't working. Till now in my tables I store the dates as a <code>string</code>, but I assume this isn't the right way... So I created a table:</p>

<pre><code>CREATE TABLE "TRANSACTIONS" (
    "date" DATETIME,
    ...
}
</code></pre>

<p>I want to store the date like <code>2016-11-04 10:50</code>, so I use:</p>

<pre><code>String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
</code></pre>

<p>I use <code>prepared Statements</code> to insert records in DB and when I try to do this:</p>

<pre><code>stm.setDate(1, timeStamp); 
</code></pre>

<p>I get that <code>String cannot be converted to Date</code>. So I convert it to <code>DATE</code></p>

<pre><code>String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date datee = formatter.parse(timeStamp);
</code></pre>

<p>and then I get <code>java.util.Date cannot be converted to java.sql.Date</code> so I tried this:</p>

<pre><code>String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
java.sql.Date sqlDate = java.sql.Date.valueOf(timeStamp); 
</code></pre>

<p>which when I run it, I get <code>java.lang.IllegalArgumentException</code></p>