Babak Fakhriloo
Babak Fakhriloo

Reputation: 2126

dealing with date field in sqlite for android application

I have defined insert method for my table in android application as follow :

public long CreateBirthDay(long id,Date _date)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_ID, id);
    initialValues.put(KEY_Date, dateFormat.format(_date));

    return mDb.insert(DATABASE_TABLE, null, initialValues);
}

But I dont know how to get date from cursor. I mean I cant complete the below code:

 bc.SetID(mCursor.getLong(mCursor.getColumnIndex(KEY_ID)));

 bc.SetDate(?);

Regards.

Upvotes: 1

Views: 4518

Answers (2)

Vyacheslav Shylkin
Vyacheslav Shylkin

Reputation: 9791

bc.SetDate(dateFormat.parse(mCursor.getString(mCursor.getColumnIndex(KEY_Date))));

Upvotes: 3

SathishBabu S
SathishBabu S

Reputation: 372

insert datetime as numeric using following function.

long time=datetime.gettime();

agagnin use the Date date =new Date(cursor coloumn index) to get the date object.

Upvotes: 0

Related Questions