2

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.

1 Answer 1

9

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"
}
1
  • 1
    Thanks. it's Worked Commented Apr 7, 2020 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .