3

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
2
  • 1
    "2016-12-14T02:01:20.983".split("T")[0] 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. Commented Dec 14, 2016 at 7:56

3 Answers 3

2

You can just do this,

CreatedDate: o.createdDate.format("yyyy-mm-dd");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sir your solution is awesome.
2

You cant format date like so:

$filter('date')(date, format, timezone)

or

{{ date_expression | date : format : timezone}}

source: https://docs.angularjs.org/api/ng/filter/date

Comments

0

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.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js"></script>

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.