0

We have built LDS forms using lightning-record-edit-form, lightning-input-field tag is used for date which displays standard locale date format as per documentation. The problem is, it is always displaying date in medium format of locale i.e. Jul 1, 2021 not in short format 06/01/2021. Any pointers to display date in mm/dd/yyyy format using lightning-input-field? Is this a salesforce limitation?

We cannot change the tag to lightning-input field and add apex since such change will defeat the purpose of using LDS and will result in revamp of all 20+ forms just for 1 date format issue.

2
  • I believe this is something with setting of your user. For me with CZ locale i have displayed the date as 28.2.2022, if i login as someon with EN locale i have it like 2/28/2022.
    – Damecek
    Sep 3 at 7:27
  • User is using en_US locale, only in LDS form with lightning-input-field is showing date in medium format instead of short format otherwise in lightning experience it is mm/dd/yyyy Sep 3 at 7:32
0
handlesubmit(event){
   event.preventDefault();  
   console.log('handle submit');

   const fields = event.detail.fields;
   fields.Travel_Dates_Sent_to_PS__c = false;

   if (this.updatetype=="cancel"){
      let todaydate = this.formatDate();
      fields.Travel_End_Date__c=todaydate;
   }
   this.template.querySelector('lightning-record-edit-form').submit(fields);
}

formatDate() {
   console.log('formatDate');
   let d = new Date();
   let month = '' + (d.getMonth() + 1);
   let day = '' + d.getDate();
   let year = d.getFullYear();
   if (month.length < 2) 
       month = '0' + month;
   if (day.length < 2) 
       day = '0' + day;
   return [day, month ,year,  ].join('/');
}

Please refer this link for more details

1
  • 1
    Links can stop working so it'd be great if you can add some of those relevant details to your answer with an edit Sep 3 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.