2

I tried showing MSSQL data in a HTML table using Angular JS ng-repeat. My date column field is shown in detailed with timezone etc:

{"date":"2016-12-11 00:00:00.000000","timezone_type":3,"timezone":"UTC"}

I just want to show the date alone. How to format that?

<tr ng-repeat="bill in allbills | filter : search" >
    <td>{{ $index + 1 }}</td>   
    <td>{{ bill.bill_Date }}</td> 
</tr>
1

1 Answer 1

1

You need to use the date filter:

{{ date_expression | date : format : timezone}}

Your <td> should look something like this to display only date:

<td>{{ bill.bill_Date | date:'yyyy-MM-dd'}}</td>

EDIT

You can also write a custom filter since you are already getting the date in correct format. Check this fiddle with working code:

HTML

<div ng-app="myApp" ng-controller="myCtrl">
  <span>{{ bill.bill_Date.date | date}}</span>
</div>

JS

angular.module('myApp', [])
  .controller('myCtrl', function($scope) {
    $scope.bill = { // from row set
      'bill_Date': {
        "date": "2016-12-11 00:00:00.000000",
        "timezone_type": 3,
        "timezone": "UTC"
      }
    };
  })
  .filter('date', function() {
    return function(input) {
      return input.split(' ')[0];
    }
  });
Sign up to request clarification or add additional context in comments.

3 Comments

i used like this <td>{{ bill.bill_Date | date:'yyyy-MM-dd'}}</td>. but stil it displays with complete format.. remember it comes from SQL Server rowset.. it displays {"date":"2016-12-11 00:00:00.000000","timezone_type":3,"timezone":"UTC"}
Do you want to display it as 2016-12-11 ?
I've added a custom filter, check it out.

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.