My date-column is of type integer:
myDate.getTime() //long saved in db
During my research on how to best sort upcoming birthdays, I found this: MySQL query to sort upcoming birthdays based on current date
I've tried to translate the solution into SQLite syntax, but with no luck. Anyone want to push me in the right direction?
I'm not even able to get for instance the month of a timestamp:
strftime('%m', birthday) //unexpected value (dec = 1, jan = 1, jan = 6)
strftime('%m', 'now') // as expected (mar = 3)
Any help appreciated.
UPDATE Ok, now I have really created a mess:
cur = db.rawQuery("SELECT "
+ "(strftime('%Y','now') - strftime('%Y',datetime(("+BIRTHDATE+"/1000), 'unixepoch', 'localtime'))) AS age,"
+ "date((" + BIRTHDATE + "/1000),'+' || age || ' year') AS currbirthday,"
+ "date((" + BIRTHDATE + "/1000),'+' || age+1 || ' year') AS nextbirthday"
+ " FROM " + TABLE
+ " ORDER BY CASE"
+ " WHEN currbirthday < date('now') THEN nextbirthday"
+ " ELSE currbirthday"
+ " END", null);
Error: "No such column age"
Ok, well, I tried putting the entire expression calculating "age" inside the concat, but the result is strange(age stores the correct value):
Log.d("bdate", contact.getFirstname() + ": currbday=" + cur.getString(1));
Log.d("bdate", contact.getFirstname() + ": nextbday=" + cur.getString(2));
Samantha: currbday=-5705--6--29
Samantha: nextbday=-5704--6--29
Any suggestions?