Lilith
Lilith

Reputation: 165

Date null in angularJS

I have an application where my date displays "null" when I put my filter and I do not understand why..

Without my filter, the date is displayed as follows:

2018-07-05 00:00:00.000000

but when I put the following things it shows me "null"

my filter :

.filter('dateOnly', [
'$filter', function($filter) {
    return function(input, format) {
        return $filter('date')(new Date(input), format);
    };
}
])

in my view :

<span> {{ element.dateVisite.date | dateOnly: "dd MMMM y"}}</span>

if anyone could help me please

Upvotes: 1

Views: 1922

Answers (1)

Priyanka Jethwa
Priyanka Jethwa

Reputation: 77

Try this,

<label ng-bind="formatDate(date) |  date:'dd/MM/yyyy'"></label>

 $scope.formatDate = function(date){
      var dateOut = new Date(date);
      return dateOut;
};

Output will be something like this 15/12/2014

Note: If you are using a string date of format "2014-12-19 20:00:00" string format (passed from a PHP backend), then you should modify the code to the one in: https://stackoverflow.com/a/27616348/1904479

Hope this helps:)

Upvotes: 1

Related Questions