0

I am trying to filter a dataset to a daterange. I am using a datepicker for this:

app.directive('datetimez', function() {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, element, attrs, ngModelCtrl) {
      element.datetimepicker({
        dateFormat: 'dd-MM-yyyy',
        language: 'en',
        pickTime: false,
        startDate: '01-11-2013', // set a minimum date
        endDate: '01-11-2030' // set a maximum date
      }).on('changeDate', function(e) {
        ngModelCtrl.$setViewValue(e.date);
        scope.$apply();
      });
    }
  };
});

The daterange filter looks like this:

app.filter('dateRange', function() 
{
  return function(input, dateFrom, dateTo) 
  {
    console.log('daterange filter kicksin');
    console.log(dateFrom);
    console.log(dateTo);

    return _.filter(input, function(d) {
      var testing= Date.parse(d.date) >= Date.parse(dateFrom) && Date.parse(d.date) <= Date.parse(dateTo)
      //console.log('testing filter result:',testing);
      console.log(testing);
      return testing;
    });

  }
});

The only problem is that the datepicker spits out this kind of dateformat: "2015-08-03T13:15:05.158Z". How can I convert this so I can do the comparison in my filter?

plunkr:http://plnkr.co/edit/7IdepM20bH7cOol5m2LH?p=preview

Pindakaas
  • 4,389
  • 16
  • 48
  • 83

0 Answers0