Reputation: 634
i want to insert date in Sqlite database i'm stuck at this point. I have taken Date datatype in my pojo class. now i want to insert that thing in my Sqlite Databse using contentvalue so what should i do. it is like this.
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
String a = String.valueOf(dp.getDob());
cv.put(DOB, a);
in pojo class
Date dob;
public DoctorPojo( String name,Date dob,String gender, String adder,String city,
String cas,String mobile, Date date,String disease)
{
this.name = name;
this.dob = dob;
this.gender = gender;
this.adder = adder;
this.city = city;
this.cas = cas;
this.mobile = mobile;
this.date = date;
this.disease = disease;
}
Upvotes: 0
Views: 2849
Reputation: 51
According to the Sqlite specficication https://www.sqlite.org/lang_datefunc.html , You have to store Date as String with format YYYY-MM-DD.
It's easy to do that with SimpleDateFormatter.
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = formatter.format(dp.getDob());
cv.put(DOB, formattedDate );
Upvotes: 1