I’m querying my database to display the row based on the date column. I’ve got the method to function correctly, but I’m having to change the format of my date values in the database. Previously, I had the dates as yyyyMd which would get 201252 for today for example. Then I parsed the date into a Long and passed it into my method
String sd = hiddenDate.getText().toString();
long aLong = Long.parseLong(sd);
dba.open();
String[] rScr = dba.getTodayMethod(aLong);
But I’m having to rewrite the date format into yyyy-M-y. Then the dashes in the date are breaking the “parseLong” I think. And it appears that just passing the sd variable into the getTodayMethod, like String[] rScr = dba.getTodayMethod(sd); doesn’t work either. So what should I parse the String sd into to accomodate the dashes in the date? and how would that parse code be written?
Fundamentally, you’re doing the wrong thing by trying to parse it as a long to start with. It’s not the textual representation of a 64-bit integer – it’s the textual representation of a date. So use types that are to do with date/time.
Personally I like using Joda Time, but if you’re on Android that may be too big for you – in which case you’ll have to use
java.util.Dateandjava.util.Calendar, horrible though they are, and then usejava.text.SimpleDateFormatfor the parsing. (Don’t forget to set the locale and time zone appropriately…)