Muhammad Umar Muhammad Umar - 6 months ago 14
Android Question

Retrieving string from SQlite and converstion to sql date

i have used the following Code to save date into DB of Sqlite

( java.sql.Date)


public String dateToDB ( Date date)
{
String convertedDate = date.toString(); // yyyy-mm-dd
return convertedDate;
}


How can i convert the recovered String into date?

private Date dateFromColumn(String columName, Cursor result)
{
// ???????
return date
}

Answer

I found this in the Docs:

Date.valueOf(String dateString) creates a Date from a string representation of a date in SQL format: yyyy-MM-dd

This means four you:

private Date dateFromColumn(String columName, Cursor result)
{
  String strDate = result.getString(result.getColumnIndex("yourcolumnname..."));
  return Date.valueOf(strDate);   
}