Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In database table I use a date format which inserts date like 04-04-2015.
Then using a datePicker through variable 'from_date' I choose the same date and that date is like 4-4-2015. If I want to select rows using the date selected from datepicker I get no rows even though rows are available. How to change the datePicker date to 04-04-2015 from 4-4-2015 or how to insert the date like 4-4-2015 instead of 04-04-2015.


Java
    private DatePickerDialog.OnDateSetListener myDateListener
            = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
            dateView.setText(new StringBuilder()
            // Month is 0 based so add 1
            .append(arg3).append("-") //day
            .append(arg2+1).append("-")//month
            .append(arg1).append(" "));//year
            from_date=dateView.getText().toString();
            startActivity(new Intent( datefrom.this, dateto.class));
}
    };


Code for insertion:
Java
contentvalues.put(VivzHelper.TX_DATE,new SimpleDateFormat("dd-MM-yyyy").format(new Date()));
Posted
Updated 19-Apr-15 7:37am
v2
Comments
Richard MacCutchan 19-Apr-15 13:22pm    
Why? Use DateTime variables so your code may work. Also there is no need to call ToString on Text fields.
Maciej Los 19-Apr-15 13:38pm    
Which question is still active: "How to change the datePicker date to 04-04-2015 from 4-4-2015 or how to insert the date like 4-4-2015 instead of 04-04-2015."?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900