Pramod
Pramod

Reputation: 1461

How to compare current date with date from the picker

I have a datetimepicker which i used to get the date and set it as label in my screen. Now i want to check if the entered date is valid or not. i.e., the entered date should be bigger than or equal to the current date. Please tell with a code. Thank you

StringBuffer dateStrDate = new StringBuffer();

Calendar Cal = datePickerDate.getDateTime();

SimpleDateFormat dateFormat = new SimpleDateFormat("yy:mm:dd"); dateFormat.format(Cal, dateStrDate, null);
time.setText(dateStrDate.toString());

Upvotes: 1

Views: 270

Answers (1)

Yair Nevet
Yair Nevet

Reputation: 13003

DateTimePicker datePicker = DateTimePicker.createInstance(Calendar.getInstance(), "yyyy-MM-dd", null);
if(datePicker.doModal()) {
    Calendar cal = datePicker.getDateTime();
    int month=cal.get(cal.MONTH);
    int year=cal.get(cal.YEAR); 
    int date1=cal.get(cal.DATE);
}

Upvotes: 2

Related Questions