I am try to write a validation rule using javaScript. Date range should not be greater than 90 days.In order to do that,I have created two date fields and directly access in Visualforce page and the date format is dd/mm/yyyy.

Now whenever I try to find difference between these two dates using javaScript, JavaScript function convert these two input in mm/dd/yyyy format.Thus I am getting wrong validation.

I used different date format function but unfortunately it didn't work.

Please help me !!!!


  • 2
    Could you show us the code you are currently using? Commented Mar 6, 2013 at 13:24
  • Have you tried this: stackoverflow.com/questions/3828890/… and this: stackoverflow.com/questions/802861/… Commented Mar 6, 2013 at 13:25
  • If you use APEX, there's a built in function called daysBetween that returns the number of days between a particular date and a compareDate.
    – crmprogdev
    Commented Mar 6, 2013 at 15:22
  • 5
    Why wouldn't you put the validation rule on the object itself? Client side will only keep your data sane for that interface.
    – joshbirk
    Commented Mar 6, 2013 at 15:54

1 Answer 1


Build a utility function to convert like this...

// accepts format like dd/mm/yyyy
function parseDate(datestr) {
  var arr = datestr.match(/(\d+)/g);
  var y = parseInt(arr[2]);
  var m = parseInt(arr[1])-1;
  var d = parseInt(arr[0]);
  return new Date(y,m,d);

parseDate('23/07/1980'); // => Wed Jul 23 1980 00:00:00 GMT-0400 (EDT)
  • No problemo! Happy to help! Commented Mar 7, 2013 at 13:45

You must log in to answer this question.

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