List Library not filtering Date Value

Hey Plumsail,

I'm trying to filter my list/library control using a date field but it's not returning any results.

This is the code I'm using:

//Code will filter the Workforce List/Library Control based on Date
    WorkforceCOHDataTable.ready(function() {
        filterWorkforceCOHDTbyDate();
    });

    //filter List or Library with new value when Search field changes
    fd.field('Date1').$on('change', function() {
        filterWorkforceCOHDTbyDate();
    });
    
    function filterWorkforceCOHDTbyDate(){
                        if(fd.field('Date1').value){
                        //Filters Date Column
                        WorkforceCOHDataTable.filter = "<Eq><FieldRef Name='Effective_Date'/><Value Type='DateTime'>"
                        + fd.field('Date1').value + "</Value></Eq>";
                        }
       
                        else{
                            WorkforceCOHDataTable.filter = '';
                                }
                                                
                        WorkforceCOHDataTable.refresh();
}

The dataType of the "Effective_Date" field is a date field.

Upon entering the value in the Date1 field, the library tries to filter the records but doesn't return anything in the specified filter criteria.

Many thanks for your time and effort!

I've made a slight modification to my code to format the date string to using the ISODateString method, but get an error in the console:

//Code will filter the Workforce List/Library Control based on Date
    WorkforceCOHDataTable.ready(function() {
        filterWorkforceCOHDTbyDate();
    });

    //filter List or Library with new value when Search field changes
    fd.field('Date1').$on('change', function() {
        filterWorkforceCOHDTbyDate();
    });
    
    function filterWorkforceCOHDTbyDate(){
                        if(fd.field('Date1').value){
                        //Filters Date Column
                        WorkforceCOHDataTable.filter = "<Eq><FieldRef Name='Effective_Date'/><Value Type='Date'>"
                        + fd.field('Date1').value.toISOString(); + "</Value></Eq>";
                        }
       
                        else{
                            WorkforceCOHDataTable.filter = '';
                                }
                                                
                        WorkforceCOHDataTable.refresh();
}

Dear @DryChips,
Here's the correct format for date filter:

WorkforceCOHDataTable.filter = '<Eq><FieldRef Name="To"/><Value IncludeTimeValue="FALSE" Type="DateTime">2023-8-31</Value></Eq>';

To get your date to this format, try the following:

var date = new Date();
var dateString = date.getYear() + '-' + date.getMonth() + '-' + date.getDate();
WorkforceCOHDataTable.filter = '<Eq><FieldRef Name="To"/><Value IncludeTimeValue="FALSE" Type="DateTime">' + dateString  + '</Value></Eq>';