0

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 !!!!

Sunil

  • 2
    Could you show us the code you are currently using? – rael_kid Mar 6 '13 at 13:24
  • Have you tried this: stackoverflow.com/questions/3828890/… and this: stackoverflow.com/questions/802861/… – Sergej Utko Mar 6 '13 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 Mar 6 '13 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 Mar 6 '13 at 15:54
2

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);
}

//test
parseDate('23/07/1980'); // => Wed Jul 23 1980 00:00:00 GMT-0400 (EDT)
  • No problemo! Happy to help! – Kevin O'Hara Mar 7 '13 at 13:45

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.