2017-04-13 18 views
0

我有我的數據存儲在一個字段「日期」與字符串格式,我想查詢該表以顯示結果誰擁有某一年包含指定年。查詢結果至少有一個字符串格式的日期

我的問題是如何讓這一年從字符串,我目前有:

public Cursor getExpensesByYear() { 

    String sql = "SELECT * FROM " + TABLE_EXPENSE + " WHERE strftime('%Y', date) = '2015'"; 

    Cursor cursor = getReadableDatabase().rawQuery(sql, null); 
    // String inputString = cursor.getString(5); 

    // DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); 
    // try { 
    // Date inputDate = dateFormat.parse(inputString); 
    // } catch (ParseException e) { 
    // e.printStackTrace(); 
    // } 

    if (cursor != null) { 
     cursor.moveToFirst(); 
    } 

    return cursor; 
} 

它只是犯規返回任何數據。

+0

請參閱[文檔](http://stackoverflow.com/documentation/sqlite/5252/data-types/18688/date-time-types)。 –

回答

-1

我按照你的問題,但讓我推薦你,如果你需要過濾數據作爲核心功能的一部分,添加一個字段與年份,當你記錄註冊。 完成後,檢索將更快更直接。 希望它有幫助。

相關問題