Skip to content Skip to sidebar Skip to footer

How Can I Compare A Datepicker Date To The Calendar Date

A simple question I hope. How can I compare the date entered into a DatePicker to the current Calendar date? To explain, If I have the DatePicker date stored as a string, how could

Solution 1:

for example you got the date like string from datepicker then

StringsDate="05-10-2012"; // suppose you create this type of date as string thenSimpleDateFormatsdf=newSimpleDateFormat("dd-MM-yyyy");

Datedate= sdf.parse(sDate);

Calendarc= Calendar.getInstance();

c.getTime().compareTo(date);

it depending on your string or how you can get? you can get all individually from datepicker then directly set in calendar instance

Calendar my = Calendar.getInstance();
my.set(year, month, day);

now compare

my.compareTo(Calendar.getInstance());

Solution 2:

You can convert your String to Date see this

and try this compareTo

date1.compareTo(date2);

Solution 3:

read through a tutorial on dates here: http://www.mkyong.com/android/android-date-picker-example/

and this post on SO for a similar case: How to match or compare a date string with the date stored in sqlite in android?

If none of this helps then post some code and i'll edit my answer :)

Post a Comment for "How Can I Compare A Datepicker Date To The Calendar Date"