I need some help with switching the format from DD-MM-YYYY or MM-DD-YYYY to ISO Standard (YYYY-MM-DD)in JavaScript. I'm using this on a custom URL Button. This is what i'm doing, and It is working fine for US date formats but not working for EU dates. I get invalid date error.


var Lastdate = new  Date('{!ServiceContract.EndDate}'); 

How can I instantiate a Date when using a different locale?

  • Is this ServiceContract.EndDate is date field? May 1, 2017 at 19:11
  • that is correct @SantanuBoral May 1, 2017 at 19:15
  • where exactly you are facing issue? inside the custom button or some where else? May 1, 2017 at 19:21
  • It saves fine, but when I click the button that I created, then I get alert message. May 1, 2017 at 19:29
  • got the error replicated.. May 1, 2017 at 20:50

1 Answer 1


Yes, it will give an issue due to locale.

So, better retrieve year, month and day portion from the date and create a Date instance based on those parameters.

It will solve locale related issues.


var month = '{!MONTH(ServiceContract.EndDate)}'; 
var year = '{!YEAR(ServiceContract.EndDate)}'; 
var day = '{!DAY(ServiceContract.EndDate)}'; 

var Lastdate = new Date (year, month, day); 

  • Thank you this works great! I dont know why i didnt think of this approach May 1, 2017 at 21:20

You must log in to answer this question.

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