forum

Home / DeveloperSection / Forums / Date comparison Validation in android

Date comparison Validation in android

Anonymous User 3022 30-Dec-2015
I have  edit texts for start date and End date. I want to implement date validation which will check whether the end date is greater than start date or not. Please suggest me the right way.

I have tried to find out the difference between two dates in day in my code : 
             //EditText with string of start date
            dataInicio = (EditText)findViewById(R.id.ses_dpDataIni);
             //EditText with string of end date
    dataFim = (EditText)findViewById(R.id.ses_dpDataFim);
             //Convert String to calendar to check the difference between two dates..
    try{
    dateInic = dataInicio.getText().toString();
    dateFim = dataFim.getText().toString();
    calInic=Calendar.getInstance();
    calFim = Calendar.getInstance();
    calInic.setTime(form.parse(dateInic));
    calFim.setTime(form.parse(dateFim));
    }
     catch (ParseException e) { 
         e.printStackTrace(); 
    } 
    Log.w(SessaoQuotaEdit.class.getName(),"DIFERENCA DE DIAS"  +daysBetween(calInic,calFim));
    tvDiasQuotas = (TextView)findViewById(R.id.ses_tvNumDiasQuota);
    tvDiasQuotas.setText("NUMBER OF DAYS: " +daysBetween(calInic,calFim));
            //CHECK IS END-DATE IS GREATER THAN START-DATE
             .............
             .............

Updated on 28-Jun-2023
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By