Two Dates are Comparing but Time is not comparing properly. This is my Code
final String setdate = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(4)));
final String settime = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(5)));
Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat formatter1 = new SimpleDateFormat("dd/M/yyyy");
String currentDate = formatter1.format(calendar1.getTime());
Calendar calendar2 = Calendar.getInstance();
SimpleDateFormat formatter2 = new SimpleDateFormat("h:mm");
String currentTime = formatter2.format(calendar2.getTime());
if(currentDate.compareTo(setdate)>=0)
{
if(currentTime.compareTo(settime)>=0) {
myCheckBox.setChecked(true);
myCheckBox.setEnabled(false);
}
}
How can I compare two times.In database date and time field are different.So help me please.
I think you're asking how to compose a datetime from two separate fields of date and time. It's pretty simple. You can use your
SimpleDateFormat
to do it:In Java there is a method which you can compare two date and time
For you have to format your date and time in DATE format in JAVA.
After that use below code
Hope above code will help you.
Let me know if you need more help from my side.
Try this:
Very Simple. Convert both the value time1 and time2 in millisecond or minute and measaure difference.
OR
This Link for function might help you. Good Luck.