Search code examples
sqlangularjsangularjs-ng-repeatdatefilter

AngularJS: Filter date with sql date string format


I need to add a date filter which have a date property with date string value("2015-10-15T20:00:00.000Z"). This is a huge list so I can't convert every object to Date and then filter. I believe there will be any alternative to do this.


Solution

  • Try this filter:

    angular.module('yourmodule').filter('datetime', function($filter) {
        return function(input) {
            var t = input.split(/[- :]/);
    
            // Apply each element to the Date function
            var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
            console.log(d);
            return d;
        };
    
    });