You need to sign in to do that
Don't have an account?
jojoforce
How to pass an sObject that has a Date field in JavaScript Remoting?
I have a Visualforce Page that is using JavaScript remoting to essentially pass an sObject that has a Date Field into a JavaScript remoting action. However, it appears that it does not seem to recognize the javascript date format.
I have tried different variation, but it's not working. Any advice would be great.
Variations that I tried...
Also this one...
And this one...
function MyObject__c(){ this.Name = null; this.Start_Date__c = null; } function createRecord() { MyObject__c myobj = new MyObject__c(); myobj.Start_Date__c = '2017-01-01'; Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.myclass.mymethod}', myobj, function(results, event){ if (event.status) { console.log(results); } }, {escape: true} ); }
I have tried different variation, but it's not working. Any advice would be great.
Variations that I tried...
myobj.Start_Date__c = new date('2017-01-01').toUTCString();
Also this one...
myobj.Start_Date__c = new date('2017-01-01');
And this one...
myobj.Start_Date__c = new date('2017-01-01').toISOString();
Regards
Alain
Date.parse(): The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31).
Direct call: Date.parse(dateString)
Implicit call: new Date(dateString)
A string representing an RFC2822 or (a variant of) ISO 8601 date (other formats may be used, but results may be unexpected).
The parse() method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
https://tools.ietf.org/html/rfc2822#section-3.3
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse