How do I format the datetime in coreui datatable react

817 Views Asked by At

I am supposed to format the date time to display "28 Sep 2020 00:11".

my initial value is this "2020-09-28 00:11:50".

currently, this is how it is being displayed.

enter image description here

i am using coreui's datatable.

this is my code for the datatable assigning.

enter image description here

I want to know if there's any way i can format the datetime here?

2

There are 2 best solutions below

0
On

You can try this:

createdAt: (item: any) => (
    <td>
        <Moment format="DD.MM.YYYY">{item.createdAt}</Moment>
    </td>
)

Datatable has scoppedSlots prop for change any scop, I used react-moment for date formatting.

0
On

Detail I implement with good anwers @Kelvin Schoofs,@calal_mnf:

scopedSlots = {{
                'createdAt':
                  (item)=>(
                    <td>
                      <Moment format="DD/MM/YYYY hh:mm:ss">{item.createdAt}</Moment>
                    </td>
                  )
              }}

and

import Moment from 'react-moment';

This work for me ! Hope it useful for you