prefilter table with date via URL param / localization problem
prefilter table with date via URL param / localization problem

For filtering the table I have a min/max date field with a datepicker.
I use DataTables with Moments, DateTime and Bootstrap 5.
When I set the date via the datepicker it works.
Now I want to pre-filter the table via url parameter: /table?startdate=DDMMYYYY
For this I created a minimal use case here: https://live.datatables.net/nagibene/1/edit
For simple testing I wantet to test it with a string first but that seems to fail.
let urlParam = "27.07.2025";
let startDate = moment(urlParam,"DD.MM.YYYY");
The date has the format Sun Jul 27 2025 00:00:00 GMT+0200 and filtering doesn't work.
Then I saw that it's possible to change the format based on the used localization with
let startDate = moment(urlParam,"DD.MM.YYYY").format('L');
which should give me DD.MM.YYYY according to the moment.js website (German language). So I added the language translation JSON file from DataTables but that leads to an error. Without the translation file the date in the input field is formated like MM/DD/YYYY which is the englisch localization.
Questions:
- Why does the date format in the input field shows "Sun Jul 27 2025 00:00:00 GMT+0200"? Do I need the Moment localization? Is that available in DataTables?
- Why do I get errors when I add the German localization from DataTables?
- It seems that short weekday names are not available in the localization file. The datepicker in the German version shows only the full weekday names. It seems that weekdaysMin and weekdaysShort are missing in the translation file.
Object in Englisch has the following:
_weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
_weekdaysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
_weekdaysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
- Can I add weekdaysMin and weekdaysShort manually to the language localization?
Answers
I will try to answer some of your questions. I am using moment.js myself with data tables.
First you need to set the locale if you want to use it. I do this depending on the user's language.
This will transform 27.07.2025 to 20250727 if locale is set to "de".
here is a coding example. "val" is the date in German or English format depending on the user's language.
This is a different use case: I have a date in format MMDDYYYY and want to convert it to format "L" which can be either German or English format.