Dms Malith Disanayake
Dms Malith Disanayake

Reputation: 203

change date format into "DD-MM-YYYY"

I used input type "date" as below,

<input type="date" class="form-control input-sm pull-right" name="order_date" placeholder="Created At"
          id="l1" [(ngModel)]="order_date">

It gives the result with "YYYY-MM-DD" format.

I need the result as "DD-MM-YYYY" with the input type of "date'.Any idea to overcome this!

Upvotes: 0

Views: 1407

Answers (4)

joker
joker

Reputation: 1

var newDatepickerDate = new Date(23/03/1999);
var startup = newDatepickerDate.toLocaleDateString();
var datePickerdate =startup.replace(/\b(\d\/)/g,'0$1');
var i = datePickerdate;
var dayMonthYear= i.replace(/(\d\d)\/(\d\d)\/(\d{4})/, "$3-$1-$2"); 

Upvotes: 0

Vaishali Rajemahadik
Vaishali Rajemahadik

Reputation: 11

{{order_date| formatDate: order_date:'d/M/yyyy'}}

Upvotes: 1

Swoox
Swoox

Reputation: 3740

Use:

(ngModelChange)=setDate(order_date)

And in component:

setDate(date:Date){
  payload.date = date; // to save payload 
}

Upvotes: 1

Kushagra Saxena
Kushagra Saxena

Reputation: 659

Use {{date | date:'ddMMyyyy'}} instead of {{date | date:'dd MM yyyy'}}

Upvotes: 1

Related Questions