0

I'm creating a LWC with datatable that shows some of the key record values. I have just one issue - regarding the date/time formatting.

For some reason, the field is shown as: enter image description here

My goal is to show it as follow: enter image description here

I tried everything, but nothing seems to help here .. This is my code:

HTML

<template>
  <lightning-card> 
    <lightning-datatable class="slds-table_header-fixed_container slds-scrollable_x slds-border_top"
                            data={data}
                            columns={columns}
                            key-field="id"
                            hide-checkbox-column="true"
                            show-row-number-column="true">
    </lightning-datatable>
  </lightning-card>
</template>

JS

import { LightningElement } from 'lwc';
const columns = [
            {label: 'Created Date', 
            fieldName: 'CreatedDate', 
            sortable: "true",
            type: "date",
            typeAttributes:{
                hour: "2-digit",
                minute: "2-digit",
                day: "2-digit",
                month: "2-digit",
                year: "numeric"}}];

export default class FormattedDateTimeDateTime extends LightningElement {
  columns = columns;
  data = [{"CreatedDate":"2021-05-17T14:04:23.000Z"}];
}

Any help will be appreciated. Thanks !

6
  • The issue is that the "order" or display of the date and time is controlled by the User's Locale setting (help.salesforce.com/…) Commented May 17, 2021 at 16:50
  • Got it. And if I want to change the format without changing the user locale ? My goal is to show '/' between the dates and not '.'
    – Omnia
    Commented May 17, 2021 at 16:51
  • Check this SFSE link. This might work for you.
    – Saroj Bera
    Commented May 17, 2021 at 17:15
  • Tried it .. unfortunately no luck
    – Omnia
    Commented May 17, 2021 at 17:24
  • @Omnia you would have to write your own table to get the formatting you are looking for Commented May 17, 2021 at 18:27

0

You must log in to answer this question.