I am getting the data by push it into an array and I want to show that data on a page I am using
$.each(data, function (i, o) {
$scope.GetBlogDetailsar.push({ Id: o.id, Title: o.title, CategoryId: o.categoryId, SubCategoryId: o.subCategoryId, Image: o.image, MetaDescription: o.metaDescription, TotalLikes: o.totalLikes, TotalDislikes: o.totalDislikes, CreatedDate: o.createdDate, CategoryName: o.categoryName, SubCategoryName: o.subCategoryName });
});
where GetBlogDetailsar is an array.
I am getting the desired data but the problem is I am getting the created date with time also I only need date to display So how can I remove time from date.
I am getting
`2016-12-14T02:01:20.983 as created date`
I want only
2016-12-14
I am getting the data by push it into an array and I want to show that data on a page I am using
$.each(data, function (i, o) {
$scope.GetBlogDetailsar.push({ Id: o.id, Title: o.title, CategoryId: o.categoryId, SubCategoryId: o.subCategoryId, Image: o.image, MetaDescription: o.metaDescription, TotalLikes: o.totalLikes, TotalDislikes: o.totalDislikes, CreatedDate: o.createdDate, CategoryName: o.categoryName, SubCategoryName: o.subCategoryName });
});
where GetBlogDetailsar is an array.
I am getting the desired data but the problem is I am getting the created date with time also I only need date to display So how can I remove time from date.
I am getting
`2016-12-14T02:01:20.983 as created date`
I want only
2016-12-14
Share
Improve this question
edited Dec 14, 2016 at 8:07
Mistalis
18.3k14 gold badges77 silver badges97 bronze badges
asked Dec 14, 2016 at 7:48
Gaurav_0093Gaurav_0093
1,0307 gold badges30 silver badges58 bronze badges
2
-
1
"2016-12-14T02:01:20.983".split("T")[0]
– Ajay Narain Mathur Commented Dec 14, 2016 at 7:56 - 1 If you want it only in view then you can do: {{CreatedDate | date:'yyyy-mm-dd'}}. If you want the changed date format in controller for further processing then you need to inject the date filter. – Bharat Gupta Commented Dec 14, 2016 at 7:56
3 Answers
Reset to default 2You can just do this,
CreatedDate: o.createdDate.format("yyyy-mm-dd");
You cant format date like so:
$filter('date')(date, format, timezone)
or
{{ date_expression | date : format : timezone}}
source: https://docs.angularjs/api/ng/filter/date
Can also use Moment.js to format date
Below is snippet
var dateTime = moment('2016-12-14T02:01:20.983').format('YYYY-MM-DD');
console.log(dateTime);
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/moment.js/2.17.1/moment.js"></script>