I have an object with a field of type Date. When I use the field in a trigger, it returns a date using this format: "Sun Jan 05 2011 00:00:00 (EDT)". var d = new Date("{!mydate}"); // Sun Jan 05 2011 00:00:00 (EDT) return d.getDate(); // will return 5 However, when I use the field in a "server-side validation" or in a template, it returns a date using this format: "dd/mm/yyyy". var d = new Date("{!mydate}"); // 05/01/2011 return d.getDate(); // will return 1 instead of 5 My scripts run as-is within triggers, but I need to reformat the date with server-side validations or templates. Shouldn't it behave the same way it all cases?
1, Sun Jan 05 2011 00:00:00 (EDT) - this is JavaScript format, which should be always used in any JavaScript
2. 05/01/2011 - this is user-selected format for UI and templates.
I just verified that Server-side validation uses JavaScript format. Can you provide steps to reproduce the problem? Please submit support request to follow-up.
Done. I submitted a ticket with a test object.
The problem still exists. The JavaScript date format is not properly returned within:
- Script Components
- Fields of type Template
- Fields of type Email Template
I updated the ticket.
UI Script Components and Templates use HTML format, not JavaScript. So date is formatted according to user's preferences.
This problem is now solved.
I just need to add the suffix "#js" to my date token.
This way, it always returns a date in javascript format (instead of user's preferences format).
var d = new Date("{!mydate#js}");
PS: This is not yet documented in Rollbase in action