Sanjoy Debnath Sanjoy Debnath - 6 months ago 46
AngularJS Question

Angular Date Format Not Working

I have a Html like this.

<select name="paymentList" class="form-control" tabindex=""
ng-focus="true"
ng-disabled="!showRoomPaymentList"
move-focus-by-enter-key
ng-model="paymentList"
ng-options="s.FromDate | date: 'dd-MM-yyyy' + ' To ' + s.ToDate|date:'dd-MM-yyyy' for s in showRoomPaymentList track by s.PaymentDurationId"
ng-required="true">
<option value="">--Select Payment Duration--</option>
</select>


Output like this:
01-06-2016 To 2016-06-30T00:00:00
But I want It like this
01-06-2016 To 30-06-2016

Second part date format not working how to solve?

Answer

The solution is to pack 'subexpression with filter' in () as in (anydate|date:'yyyy').

So, in your case:

s.FromDate | date: 'dd-MM-yyyy' + ' To ' + s.ToDate|date:'dd-MM-yyyy' 

change to

(s.FromDate | date: 'dd-MM-yyyy') + ' To ' + (s.ToDate|date:'dd-MM-yyyy')

See http://jsfiddle.net/jsggspm0/