android - Getting date difference in sqlite -
i want date difference between today , expiring day. code implemented. not returning right output.
public string[] getdayslist(){ cursor cursor = db.query("coupon", null, null, null, null, null, null ); if(cursor.getcount()<1){ cursor.close(); return null; } string[] array = new string[cursor.getcount()]; int i=0; while(cursor.movetonext()){ string days = "(julianday('now') - julianday(expired_date))"; array[i] = days; i++; } return array; }
this returns (julianday('now') - julianday(expired_date))
. please me date difference string array here.
the now
modifier returns not date time.
to change timestamp start of date, use date() function:
select julianday(date('now')) - julianday(expired_date) ...
(if expired column contains time values, have use date()
it, too.)
and execute this, have give database:
public string[] getdayslist() { string days = "julianday(date('now')) - julianday("+expired_date+")"; cursor cursor = db.query("coupon", new string[]{ days }, // query returns 1 column null, null, null, null, null); try { string[] array = new string[cursor.getcount()]; int = 0; while (cursor.movetonext()) { array[i++] = cursor.getstring(0); // read column } return array.length > 0 ? array : null; } { cursor.close(); } }
(and number of days not string; consider using int[]
instead.)
Comments
Post a Comment