我的日期列是整数类型:
myDate.getTime() //long saved in db
在我研究如何最好地对即将到来的生日进行排序时,我发现了这一点: MySQL query to sort of tomorrows based on current date
我试图将解决方案翻译成 SQLite 语法,但没有运气。有人想把我推向正确的方向吗?
例如,我什至无法获得时间戳的月份:
strftime('%m', birthday) //unexpected value (dec = 1, jan = 1, jan = 6)
strftime('%m', 'now') // as expected (mar = 3)
任何帮助表示赞赏。
更新 好的,现在我真的弄得一团糟:
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);
错误:“没有这样的列年龄”
好的,好吧,我尝试将计算“年龄”的整个表达式放在 concat 中,但结果很奇怪(年龄存储了正确的值):
Log.d("bdate", contact.getFirstname() + ": currbday=" + cur.getString(1));
Log.d("bdate", contact.getFirstname() + ": nextbday=" + cur.getString(2));
萨曼莎:currbday=-5705--6--29
萨曼莎:下一个生日=-5704--6--29
有什么建议么?