0

I am trying to find min of two dates as given below. MIN(date1,date2).But i am facing an error like Method does not exist or incorrect signature: void min(Date, Date) how can we find minimum of two dates.

1

Probably best to add your own static method either into the class where you need the minimum (make it private) or a utility class (make it public). This version handles nulls:

private static Date min(Date d1, Date d2) {
    if (d1 != null && d2 != null) return d1 < d2 ? d1 : d2;
    else if (d1 != null) return d1;
    else if (d2 != null) return d2;
    else return null;
}
1

You can use standard compare functions:

Boolean date1IsSmaller = false;
if (date1 < date2){
    date1IsSmaller = true;
}
  • This can throw NullPointerException if date1 or date2 is null. – sfdcfox Jan 28 at 18:04
  • Yes, it's a snippet. Just the important bits. – AvailableName Jan 28 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.