0

How do I format date like "Tue 01/19/2016" to show as `"Tuesday, January 19"

I tried

$scope.date = "Tue 01/19/2016";
<p>{{date | date:'EEEE/MMMM/d'}}</p>

output

"Tue 01/19/2016"

Is there a way to format it to show as Tuesday, January 19

Update: Got it working.

var date = new Date("Tue 01/19/2016")
{{date | date: 'EEEE, MMMM d'}}

Thanks

2
  • All the format types can be found on Angular's docs for Date Filter API Commented Jan 13, 2016 at 12:19
  • 1
    Make it easy for yourself include moment.js for angular: github.com/urish/angular-moment Commented Jan 13, 2016 at 12:20

3 Answers 3

4

You have to make a date object.

$scope.date =  new Date("Tue 01/19/2016");

Than you can use the date filter

{{date | date:'EEEE/MMMM/d'}}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I also got it working. I'll accept this answer.
1

The date variable cannot be a string like this. The AngularJS documentation says:

Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ).

So, one option is to define the $scope.date variable as a Date object like this:

$scope.date = new Date('2016-01-19');

Also, your filter string needs to be changed to output your desired result:

<p>{{ date | date:'EEEE, MMMM d' }}</p>

But, as you see, the date string is not the same as you have, so if you are receiving it string from an external source in your app (e.g. from an API), you'll have to manually convert it to a compatible string format, which can be directly the AngularJS compatible string format (as in the docs), or one of the Date object compatible string options. The Date.parse() method may also help you.

Comments

0

Try this:

{{date | date:'EEEE, MMMM, dd'}}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.