我是新來的android和我有問題獲取總金額大於日期('現在')。我將sqlite數據庫中的日期存儲爲INTEGER,將我的金額列存儲爲Real。我從DatePicker的服用日期和使用使用sqlite的總金額
@Override
public void onDateSet(DatePicker view, int selectedYear,int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
Calendar c=Calendar.getInstance();
c.set(selectedYear, selectedMonth, selectedDay);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
long dateInMillis=c.getTime().getTime();//I am putting this variable into date column in sqlite
這裏將其轉換爲毫秒是我的查詢
String selectTotalAmountQuery = "select sum(amount) as total from entry where"+ "d_date>date('now')";//entry is my table name
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectTotalAmountQuery, null);
double amount=0;
if (c.moveToFirst()) {
amount = c.getDouble(c.getColumnIndex("total"));
Log.i("TotalAmount :",amount+"");
c.close();
}
db.close();
記錄輸出 總金額:0.0
我知道有可以做的其他方式這不使用日期函數但我想知道這是可能的使用日期('現在')函數?
它的工作!我可以將你的答案投票,因爲我的聲望低於15,但是一旦我超過了15的聲望,我會投你的答案。謝謝 – Brother 2014-08-31 20:36:42