DateTime feature request

DateTime feature request

kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948

Using DateTime with date range filters can be problematic if the table dates aren't ISO format. DateTime returns the date with the local time. This doesn't work well when using moment to parse the dates. Use this example from this thread to see the problem. Choose June 16 for the min date and the following will appear in the output for the row with June 16:

min date date: Thu Jun 16 2022 05:31:26 GMT-0400 (Eastern Daylight Time)
moment date: q {_isAMomentObject: true, _i: '16/06/2022', _f: 'DD/MM/YYYY h:m A', _isUTC: false, _pf: {…}, …}

The comparison of (min <= date && max === null) will not pass so the row is hidden.

There are other threads with similar problems:
https://datatables.net/forums/discussion/71518/date-range-filter-with-dd-mm-yyyy-format#latest
https://datatables.net/forums/discussion/71488/issue-with-datatables-date-range-filter

There are additional steps needed when using moment. What are the recommended ways to combine comparing moment objects with DateTime objects?

This one suggests there is some inconsistency with returning the time.
https://datatables.net/forums/discussion/73126/issue-with-datatables-datetime-value#latest

The request is to either provide a way to just create a date only DateTime object or provide documentation and examples of how this works to eliminate confusion with just the generic example.

Kevin

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Hi Kevin,

    Excellent point - this has come up a few times recently. The Javascript Date object doesn't have the option of being a date only, so what I've done is to add a little bit to DateTime that will initialise the time to be 0 when the is no time component in the format.

    The upshot of that is that in the generic example if you select 11th August 2013 for the min value it will now correctly match a single row.

    Best,
    Allan

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948

    Perfect, thanks.

    Kevin

Sign In or Register to comment.