filtring between two dates when haver time

filtring between two dates when haver time

jjcfidalgo@gmail.comjjcfidalgo@gmail.com Posts: 11Questions: 8Answers: 0
edited November 2021 in SearchBuilder

when I try to filter between two dates that are datetime it doesn't show me the day itself.
For example records between 12/11/2021 until 12/11/2021. But if you put the 11/13/2021 it already works.
html:

<div class='container-fluid' style='margin-top: 10px;'>
                       <div class='row'>    
                           <div class='col-md-12 col-ms-12'>    
                               <div class='panel panel-primary'>
                                     <div class="panel-heading">Pesquisa entre datas</div>
                                     <div class='panel-body'>
                                         <form>
                                            <div class='form-row'>
                                                <div class="form-group  col-md-4">
                                                    <label>Data Inicial</label>
                                                    <input type="text"  id="min" name="min">
                                                </div>
                                                <div class="form-group  col-md-4">
                                                    <label>Data Final</label>
                                                    <input type="text"  id="max" name="max" >
                                                </div>
                                                <div class="form-group  col-md-4">
                                                    
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div  class='row'>
                                <div class='col-md-12 col-ms-12'>
                                    <table id='listainv' class='table table-striped table-bordered'style="width:100%;margin-top:5px; background-color:#748D96 !important">
                                        <thead>
                                            <tr>
                                                <th>Data</th>
                                                <th>Descricão</th>
                                                <th>Status</th>
                                                <th></th>
                                            </tr>
                                        </thead>
                                        <tbody><tr><td>12/11/2021</td><td>Inv-1 / 12/11/2021 00:00:00-Administrador de Sistema</td><td>Pendente</td><td><button id='btn!!!%3a91768bc2d33eccbe7b548' class='btn btn-first'><span class="glyphicon glyphicon-arrow-right"></span></td></tr></tbody>
                                    </table>
                                </div>
                           </div>
                       </div>
                    </div>
</div>
            </div>"
code:
"var today =new Date();
    var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
    var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
    
    $('#min').datepicker({
    onSelect:function(){
        table.draw();
    },
  autoclose: true}).val(GetfDate(firstDay));
    $('#max').datepicker({
    onSelect:function(){
        table.draw();
    },
  autoclose: true}).val(GetfDate(lastDay));

    
    var table = $('#listainv').DataTable();

    $.fn.dataTable.moment('MMMM D YYYY HH:mm');
    $.fn.dataTable.ext.search.push(
        function(settings, data, dataIndex) {
            min =$("#min").val();
            var max = $('#max').val() ;
            
            var startDate = data[0];
           
       
            if (startDate <= max && startDate >= min) 
            {
            
                return true;
            }
            else
            {
     
                return false;
            }

        }
    )
})    
 function GetfDate(data) {
    var tdate = data;
    var dd = tdate.getDate(); //yields day
    var MM = tdate.getMonth(); //yields month
    var yyyy = tdate.getFullYear(); //yields year
    var currentDate= dd + "/" +(MM+1) + "/" + yyyy;
 
    return currentDate;
 }

why?

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    It seemed your message was caught in the spam filter, apologies for that.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.