Format DateTime in DataGrid

Hi,

I am passing the results from a search query to the items of a DataGrid.

One of the fields is a datetime.

When the DataGrid renders the datetime it is in this format - “2024-04-02 00:00:00+00:00”

How can i control the way this text is formatted e.g. “2024-04-02 00:00”

thanks

Stick a label in the data grid, then just use strftime.

So, something like:

self.label.text = self.item[‘date’].strftime(‘%d%m%y’)

Also note that displaying datetimes in data grids will display the server time zone, not the local time zone. You can see a custom component that fixes this here: Local Timezone Display in Data Grids

You can look at the source for that component to see the technique if you don’t want to use the component directly.

1 Like

… Or use the same syntax in the databinding

Thank you. I ended up doing this,

1 Like