How to find whether two dates are same using apex in Salesforce?

How to find whether two dates are same using apex in Salesforce?

Sample Code:

DateTime:

DateTime myDate = datetime.now();
DateTime dueDate = 
DateTime.newInstance(
    2008, 1, 30
);
//return true if myDate and dueDate are same else return false
Boolean dueNow = myDate.isSameDay(
    dueDate
);

Date:

Date myDate = Date.today();
Date dueDate = Date.newInstance(
    2008, 1, 30
);
//return true if myDate and dueDate are same else return false
Boolean dueNow = myDate.isSameDay(
    dueDate
);

Leave a Reply