Datatable datetime format

I have data from a pandas dataframe that I want to put in a datatable. The first field is a date. It’s formatted YYYY-MM-DD in pandas. In the dataframe it’s format is YYYY-MM-DDT00:00:00. How do I get time out of the format in the dataframe? In all of the examples in the DataTable user guide dates are in YYYY-MM-DD format.

This worked properly in an earlier version of Dash and DataTable (I believe the version of Dash was 0.4).

I’m also having this issue. Anyone found a fix?

I hit all my date columns with this before populating the DataTable component:

for x in ["Date Col1", "Date Col2", "Date Col3"]:
        if x in df.columns:
            df[x] = pd.to_datetime(df[x], format="%Y-%m-%d").dt.floor("d")
1 Like

That doesn’t work for me unfortunately, Dash still adds the extra ‘00:00:00’.

Assuming that your column is named as “Date_Col”, you can format it before creating the data table:

df.Date_Col = pd.DatetimeIndex(df.Date_Col).strftime("%Y-%m-%d")

That should do it.

Also refer to this documentation for further details https://dash.plot.ly/datatable/typing.

1 Like

Thanks that worked! I’ll check out that documentation