Convert a string to date for database : <p>I am trying to convert a string into a date type, so I can save the current time someone last logged in, into my database. The field in the database takes the date type only and not a string representation of it.</p>

<p>Here is my code for getting the current date and formatting it: </p>

<pre><code>DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
carrier.setLastUpdateDate(dateFormat.format(date));
</code></pre>

<hr>

<p>Error:</p>

<p><strong>incompatible types: String cannot be converted to Date</strong></p>
