Get month from data stored as string in sqlite android -
i'm getting date user , storing sting in database. example date in database looks "22/09/2014". want month(september) date. how can that?
my code is
public arraylist<string> getmonths(){ string select_mon = "select strftime('%m'," + diary_dbhandler.personal_date + ") " + diary_dbhandler.table_personal + ";"; cursor c = database.rawquery(select_mon, null); c.movetofirst(); arraylist<string> mon=new arraylist<string>(); if (c != null) { while(!c.isafterlast()) { system.out.println(mon); mon.add(c.getstring(0)); c.movetonext(); } c.close(); } return mon; }
you can date object simpledateformat
. pattern string ("22/09/2014") dd/mm/yyyy
date date = new simpledateformat("dd/mm/yyyy", locale.english).parse(string);
from date can build calendar object
calendar cal = calendar.getinstance(); cal.settime(date);
and calendar can extract month,
cal.get(calendar.month)
Comments
Post a Comment