When I insert a record into my database I want to put the date timestamp of when it was inserted so I can then run a query against a date from the Date Picker. this is how I get the timestamp when inserting
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
cal.set(year, month, day);
long mDate = cal.getTimeInMillis();
mDate is what gets inserted
and then when I want to run a query for items on that date I do this
public DateList(Calendar date){ //constructor
dt = date.getTimeInMillis();
}
Loader
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(getActivity(),Games.GAMES_URI,new String[] {Games.GAMES_ID},Games.GAMES_DATE + "=" +dt ,
null,null);
}
but the date from the date picker does not match the timestamp inserted when the right date is picked, why not?
I would suggest adding default value of datetime in DB table itself. For example in MSSQL you can set default value datetime to equal to GETDATE(), so if you add new record, database will automatically insert current datetime for you.