简体   繁体   中英

filter data by Date range Javascript-jquery

I have data from API where date format is yyyy-mm-dd. I have added a bootstrap date range picker plugin whose date format is dd/mm/yyyy.

<script type="text/javascript">
        $(document).ready(function (){
            $('#from').datepicker({
                format: "dd/mm/yyyy"
            });
            $('#to').datepicker({
                format: "dd/mm/yyyy"
            });
        });

I want to show data by filtering date range. help me.

 function show_date(){
    if ($("#from").val().length == 0 || $("#to").val().length == 0) {
         alert('All fields are required');
     } else {
         alert($("#from").val() + ' to ' + $("#to").val());
     }
}
$('.datepicker').datepicker({
    dateFormat: 'yy-mm-dd'
 });
  • formats: dd, d, mm, m, yyyy, yy
  • separators: -, /, .

Source . I have extracted it from here. You can get full year with 'yy'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM