0

I am using date filter to format my date. but it works fine for date only. But when I go with date time its not working:

<tr class='clickable-row' ng-repeat="exam in examlist" ng-click="gotoProfile(exam.id)">
<td class="custom-icon-size" style="border-left: 0px solid #e0e0e0;">{{ $index + 1 }}</td>
<td class="custom-icon-size text-left">{{ exam.examtitle }}</td>
<td class="custom-icon-size">{{ exam.batchtitle }}</td>
<td class="custom-icon-size">{{ exam.standard }}</td>
<td class="custom-icon-size">{{ exam.examdate | date:"dd MMMM , yyyy" }}</td>
<td class="custom-icon-size">{{ exam.totalmarks }}</td>
<td class="custom-icon-size">{{ exam.status }}</td>
<td style="border-right: 0px solid #e0e0e0;">{{ exam.lastupdate | date:"dd MMM , yyyy hh:mm a" }}</td>

this {{ exam.examdate | date:"dd MMMM , yyyy" }} currently but {{ exam.lastupdate | date:"dd MMM , yyyy hh:mm a" }} it remain the same. like 2017-03-16 12:02:15

Thanks

3
  • 2
    The only thing that can be happen here is exam.lastupdate may not be a date object. It may be just a string Commented Mar 24, 2017 at 8:26
  • Yes. Like @DilumN said, for the angular filter to work, it wil work if its a date object or a timestamp. For formatting in js, you can use libraries like moment.js which has good formatter functions. Commented Mar 24, 2017 at 8:35
  • @DilumN but exam.lastupdate coming form datebase and and it has datetime datatype as 2017-03-16 12:02:15 like this Commented Mar 24, 2017 at 8:56

1 Answer 1

1

If the date is string you need to convert it to date object. create a function to convert string date to date

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

{{ formatDate(lastupdate) | date:"dd MMM , yyyy hh:mm a" }}

angular.module("app",[])
.controller("ctrl",function($scope){

$scope.lastupdate = "2017-03-16 12:02:15";

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

 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 {{ formatDate(lastupdate)  | date:"dd MMM , yyyy hh:mm a" }}
    </div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.