Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite query to sort upcoming birthdays based on current date
    primarykey
    data
    text
    <p>My date-column is of type integer:</p> <pre><code>myDate.getTime() //long saved in db </code></pre> <p>During my research on how to best sort upcoming birthdays, I found this: <a href="https://stackoverflow.com/questions/7343807/mysql-query-to-sort-upcoming-birthdays-based-on-current-date">MySQL query to sort upcoming birthdays based on current date</a></p> <p>I've tried to translate the solution into SQLite syntax, but with no luck. Anyone want to push me in the right direction? </p> <p>I'm not even able to get for instance the month of a timestamp:</p> <pre><code>strftime('%m', birthday) //unexpected value (dec = 1, jan = 1, jan = 6) strftime('%m', 'now') // as expected (mar = 3) </code></pre> <p>Any help appreciated.</p> <p><strong>UPDATE</strong> Ok, now I have really created a mess:</p> <pre><code>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 &lt; date('now') THEN nextbirthday" + " ELSE currbirthday" + " END", null); </code></pre> <p>Error: "No such column age"</p> <p>Ok, well, I tried putting the entire expression calculating "age" inside the concat, but the result is strange(age stores the correct value):</p> <pre><code>Log.d("bdate", contact.getFirstname() + ": currbday=" + cur.getString(1)); Log.d("bdate", contact.getFirstname() + ": nextbday=" + cur.getString(2)); </code></pre> <blockquote> <p>Samantha: currbday=-5705--6--29</p> <p>Samantha: nextbday=-5704--6--29</p> </blockquote> <p>Any suggestions? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload