[SalesForce] Date formatting to MM/DD/YYYY in LWC datatable

How do we format the date in datatable like MM/DD/YYYY in LWC data table.

In my datatable column type is defined as date, value display in table as
Jan 10, 2020. Expecting in MM/DD/YYYY format.

{ label: "Start Date", fieldName: "Program_Start_Date__c", type: "date" },

I gone through the LWC data table Documentation:

Displays a date and time based on the locale using lightning-formatted-date-time.

Displaying Date and Time Using Type Attributes.

Type Attribute: day, era, hour, hour12, minute, month, second, timeZone, timeZoneName, weekday, year

typeAttributes: {
 day: 'numeric',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true
}

Still not works, Can anyone Please help me on this.

Best Answer

lightning-datatable internally uses lightning-formatted-date to output date field.

To output, the date in MM/DD/YYYY format set the type attribute to

typeAttributes: {
    day: "numeric",
    month: "numeric",
    year: "numeric"
}
Related Topic