0

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.

3

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"
}
| improve this answer | |

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.