Ion-datetime format


hello, i’m using this ion-datetime amd i want to get date like 12/03/2018, any help please ?


Follow link


how to use it in the html file

<ion-datetime [(ngModel)]></ion-datetime>

  <ion-datetime displayFormat="MM/YYYY" pickerFormat="MMMM YYYY" [(ngModel)]="myDate"></ion-datetime>


it doens’t work, already use it

      <ion-label>From </ion-label>
      <ion-datetime pickerFormat="D/M/YYYY" [(ngModel)]="from_date" ></ion-datetime>


send your code both .html & .ts



      <ion-label>From </ion-label>
      <ion-datetime pickerFormat="D/M/YYYY" [(ngModel)]="from_date" ></ion-datetime>
    <!-- to -->
        <ion-label>To </ion-label>
        <ion-datetime displayFormat="D/M/YYYY" pickerFormat="D/M/YYYY" [(ngModel)]="to_date" ></ion-datetime>

and .ts, it where i want to get the date like on my question


share your ts file also

  constructor(public navCtrl: NavController, public navParams: NavParams) {



can you format it please ?


click on given link they display in blue color .


let me try this. thanks


please mark as solution so easily identified by other


i get it like 2018-05-02
how to get it like Day/Mounth/Year


Use moment.js it will format for you the dates how you would like to customize it. And use this code to achieve that console.log(moment(date).format("DD/MM/YYYY")); Good to go :slight_smile:


I agree with what @gbrigens says, but that doesn’t work, i’ll show my code:


            <ion-label>Sate date</ion-label>
            <ion-datetime displayFormat="MMM DD YYYY" [(ngModel)]="date" (ionChange)="parseDate()"></ion-datetime>


  date: string;

  constructor(public navCtrl: NavController) {
    var date_to_parse = new Date();
    var year = date_to_parse.getFullYear().toString();
    var month = (date_to_parse.getMonth() + 1).toString();
    var day = date_to_parse.getDate().toString(); = year + '/' +  month + '/' + day;


    var firstStape, secondStape;
    if (,6) === "0"){
        firstStape =,5);
        if (,9) === "0"){
            firstStape = firstStape +,8);
            secondStape =;
            secondStape =;
        } = firstStape + secondStape;

I hope this helps you


I’m sorry, but this is crazy. You do not want to be doing all this brittle, ugly string manipulation at all, let alone on every single change event.

Ionic’s datetime picker deals in ISO8601 strings, which is a good thing. Simply let it do its job:

<ion-datetime [(ngModel)]="date">
date = new Date().toISOString();

All the formatting should be done away from the interaction with the date picker component, and the best way to do it is using date-fns, not moment, because it is lighter and deals directly with ISO8601 strings:

declare var require(mn: string): any;
let format = require("date-fns/format");
getDisplayDate(): string {
  return format(, "D/MM/YYYY");


Have you try to read Date Time Format? Do you understand what is displayFormat and pickerFormat? It’s better if you read the documentation for more info.

As for above, it should look like this

  <ion-datetime displayFormat="DD/MM/YYYY" pickerFormat="DD/MM/YYYY" [(ngModel)]="from_date" ></ion-datetime>