Search This Blog

Friday, October 1, 2010

Android java datetime values from String to Long to String issue

Programmer Question

Long time reader, first time poster.



In Android, capturing date from datepicker and storing as string in sqlite. Sorting by date doesn't work because they're strings (unless I'm doing it wrong.



I've googled this issue for ~5 days, and it looks like there should be a way to capture the date from the date picker, convert it to a Long, store it in sqlite as a Long, select and sort on the Long date value, then convert the Long back to a "mm/dd/yyyy" string for display. I've tried various combinations of parse statements, Date, FormatDate, etc. with no luck at all.



My actual application flow would be:
On activity start, get today's date and display it in button which calls the datepicker.
Capture new date from datepicker (if one is entered), save it as a long to sqlite.
On opening an activity showing a listview of records, select from sqlite with orderby on date (Long), convert Long to "mm/dd/yyyy" string for display in ListView.



If someone could point me at a code sample, it would be greatly appreciated - thanks!



Evan



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails