I have a EndDate field in my visualforce page. when user enter any date.it's taking the previous date.Suppose if my user enter day after tomorrow date it will take tomorrow date i have to validate that user must enter the date is not more than 24hours from current date and time how i can check

Endtime = DateTime.newInstance(enddate, Time.newInstance(timeHH, timeMM, 0, 0));

   DateTime d = System.now();

   System.debug('*******Endtime:' +Endtime);
   Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Notenterlessthanvalue'));

my code is working here i have to check if the user enter time is less than 24hours in past then i have to save the record.

1 Answer 1


You can use the Date.daysBetween(secondDate):

  • daysBetween(secondDate)
    Returns the number of days between the Date that called the method and the specified date.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .