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

4

1 Answer 1

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)
1
  • No problemo! Happy to help! 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 .