function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jojoforcejojoforce 

javascript remoting sobject with date

I have a javascript remoting with an sObject that has a date function, however, it doesn't seem like it likes the date. How do I pass an sobject with Date? 

VF Page
function MyObject__c() {
        this.name = null;
	   this.Start_Date__c = null;
	    this.End_Date__c = null;
	    
    } 

function createRecord() {
       MyObject__c myobj = new MyObject__c();

         myobj.Start_Date__c  = '2017-01-01'; 
         myobj.End_Date__c  = '2017-01-31'; 

        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.myclass.mymethod}',
            myobj,
            function(results, event){
                if (event.status) {
                
                	console.log(results);


                }
             }, 
             {escape: true}
         );		
}
Apex Controller
global class myclass {

   @RemoteAction
   global static void myAction(MyObject__c myobj) {
      insert myobj;
   }

}

I tried different variation in handling javascript date format...Nothing seems to work....Any advice would be great!
 
myobj.Start_Date__c  = new date('2017-01-01'); 
myobj.End_Date__c  = new date('2017-01-31');
myobj.Start_Date__c  = new date('2017-01-01').toUTCString(); 
myobj.End_Date__c  = new date('2017-01-31').toUTCString();



 
Alain CabonAlain Cabon
Hi,
 
function createRecord() {
       
       var mydate = Date.parse("2017-01-01");
       var myname = "JOJO";
    
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.myclass.mymethod}',

            { "Name": myname,"Start_Date__c":mydate}, 

            function(results, event){
                if (event.status) {              
                    console.log(results);
                }
             }, 
             {escape: true}
         );        
}