[SalesForce] How to pass value to date parameter in apex method from LWC JS

Please provide a proper way to call this method from LWC passing date parameter.

public with sharing class ApexClass {
    @AuraEnabled(cacheable = true) 
    public Date string apexMethod(Date z) {
        return z;
    }
}

We got date type in aura component for this situation. Any such way in LWC?

Best Answer

Hi i have used following code -

APEX Class -

  @AuraEnabled(cacheable=true)
    public static Date getDate(Date dt)
    {
        System.Debug('dt '+dt);
        return dt;

    }

and JS Code -

@wire(getDate,{dt:"2019-12-31"})
   date({data})
  { if(data){
      console.log("Data"+JSON.stringify(data));
  }
} 

or

 @wire(getDate,{dt:new Date("2019-12-31")})
    date({data})
   { if(data){
       console.log("Data"+JSON.stringify(data));
   }

    } 

And for My understanding, the date parameter accepts in YYYY-MM-DD format.