MaxGIS
MaxGIS

Reputation: 41

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());
     }
}

Upvotes: 4

Views: 1316

Answers (1)

Vidya Sagar
Vidya Sagar

Reputation: 1719

$('.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'.

Upvotes: 1

Related Questions