Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old February 11th, 2010, 12:32 PM   #1 (permalink)
New Member
 
Join Date: Nov 2009
Posts: 5
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Date Picker to save Date into SQL Database

Hello All,
Where to start? Basically I used the example Date Picker in the resources Section:

Date Picker | Android Developers

To allow the user to enter a Date. I'm then saving this Date into my Database as a string. Basically when the date is selected the values of mYear, mMonth and mDay are updated. When a commit button is clicked I create a new java.sql.Date:

Date date = new Date(mYear, mMonth, mDay);

And store this date as a string in the data base (date.toString()).

All of the above works great but when I come to allow the user to edit the saved date I'm encountering problems. I pull the date out of the database as a string and fill this string into an intent to send to the Activity for Edit. In the Edit Activity the date.tostring is "3910-03-17" which is perfect as this seems to be how the date is stored for March 17th 2010.

Now I want to set this as the current date on the android date picker. date.getYear() and date.getMonth() both work but date.getDay() returns me the value "4" I've searched on the Internet and find that date.getDay() is deprecated as are many of the other methods.

Date | Android Developers

So following that page I try and use a Calendar object but I can't find a simple way to store a Calendar into a database and get it back.

Date date = Date.valueOf(extras.getString(MyDbAdapter.KEY_DATE ));
Calendar cal;
cal.setTime(taxDate);

The above sets the year of the cal to 3910. I could start using maths to convert 3910 to 2010 but I'm assuming there is a better method?

I am saving the date in the data base as a string but you can easily go from date.toString and back again with date = Date.valueOf(string). You can't seem to be able to do this with a Calendar which can only go toString and not back. So I could save this string in the Database but how do I get it back?

Any advice would be very gratefully received.

Arigead is offline  
Reply With Quote
Sponsors
Old April 12th, 2010, 12:46 AM   #2 (permalink)
lZr
New Member
 
Join Date: Mar 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seems subtracting 1900 will do the job. RTM for Date
lZr is offline  
Reply With Quote
Reply

Bookmarks

Tags
calendar, database


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I get a "calendar month" style date picker? leecotton HTC Desire 3 February 11th, 2011 11:55 AM
Java Date Comparison with sqlite date beedge Developer 101 1 July 22nd, 2010 03:32 PM



All times are GMT -5. The time now is 11:48 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo