Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3491092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:35:43+00:00 2026-05-18T11:35:43+00:00

I am working with android + SQLite and DatePicker Widget. The DatePicker does not

  • 0

I am working with android + SQLite and DatePicker Widget.

The DatePicker does not format correctly for my SQLite insert commands. I.e, if the chosen date has a month or day less than 10, it does not insert the 0’s. For example if I choose the date “1st January 2010”, the format of the month and date is 1 and 1. This clashes with the usual SQL format of YYYY-MM-DD.

I tried to concatenate 0’s into the integers when they are less than 10 by casting them to strings and prefixing o’s by doing the following:

 // the callback received when the user "sets" the date in the dialog
private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, 
                                  int monthOfYear, int dayOfMonth) {
                if(monthOfYear < 10)
                {
                    String mm = Integer.toString(monthOfYear);
                    String m = "0" + mm;
                    mMonth = Integer.parseInt(m);
                }
                else{mMonth = monthOfYear;}


                if (dayOfMonth <10)
                {
                    String dd = Integer.toString(dayOfMonth);
                    String d = "0" + dd;
                    dayOfMonth = Integer.parseInt(d);
                }
                else{mDay = dayOfMonth;}

                mYear = year;

                updateDisplay();
            }
        };


 // updates the date in the TextView
private void updateDisplay() {
    mDateDisplay.setText(
        new StringBuilder()
                // Month is 0 based so add 1
                .append(mYear).append("-")
                .append(mMonth + 1).append("-")
                .append(mDay).append("")
                );

    selecteddate = (String) mDateDisplay.getText();

}

I was expecting this to convert 2010-1-1 to 2010-01-01. It doesnt though. Does anyone have have a simpler way of doing this so that I can get the Date into the correct format before sending it to the sqlite table?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:35:44+00:00Added an answer on May 18, 2026 at 11:35 am

    SQLite doesn’t have Date/Time data types (http://www.sqlite.org/datatype3.html), so the ” usual SQL format of YYYY-MM-DD” isn’t the usual, in this case.

    There are several date time functions (http://www.sqlite.org/lang_datefunc.html) but you can avoid those, most of the time, by just using the INTEGER data type on your date/time column and storing the epoch stamp (http://en.wikipedia.org/wiki/Unix_time).

    DatePicker returns separate values for year/month/day of month, and month is zero-indexed. This is because it’s intended to work with Calendar (as evil as that may be). So with an INTEGER column, and something like this, you can store and retrieve date/times fine:

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, datePicker.getYear());
    cal.set(Calendar.MONTH, datePicker.getMonth());
    cal.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
    long datePubStamp = cal.getTimeInMillis();
    

    Then store the datePubStamp in the INTEGER column.

    To restore a Calendar just use Calendar.setTimeInMillis(<value_from_integer_db_column>). And, you can of course get a Date from a Calendar with getTime(), and then format with SimpleDateFormat, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an Android application that stores data in a SQLite database. My
I've been working on the Android SDK platform, and it is a little unclear
I've started working on some Android applications and have a question regarding how people
Friends, I am working on Sqlite DB and I want to open, view or
I have a TextView in my android application that has a set width on
Not sure if I'm the only one who feels this... I find working with
I'm working on an Android app with a Java component and a C++ component
I'm looking to port my working Android XML parser to Blackberry, but the latter's
I have been working on Android for a few months. Now i want to
I am working with android's 9 patch image emulator to create 9 patch image.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.