Display Date Format "DD-MM-YYYY"

Hi,

How can I show the readable date in “DD-MM-YYYY”?
It is currently shown in the table: “Thu Jun 15 2017 11:17:21 GMT + 0200 (CEST)”

This is my code:

00.collection.coffee

		id_instagram:
			type: String
			label: "* ID Instagram"
			max: 200

		createdAt:         #  <-- here
			type: Date
			autoValue: ->
				if(this.isInsert)
					new Date;
				else if(this.isUpsert)
					return { $setOnInsert: new Date };
				else
					this.unset();

		updatedAt:    #  <-- here
			type: Date,
			autoValue: ->
				if(this.isUpdate)
					new Date();
			optional: yes

		img:
			optional: yes
			type: [String]
			label: 'Immagini'

reportpage.js

TabularTables ={};

Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);


Template.reportpage.helpers({
  selector () {
    if (!!Meteor.userId()) {
      return { owner: Meteor.userId() };
    }
  },
});

TabularTables.Dealers = new Tabular.Table({
  name: "Dealers",
  collection: Dealers,
  autoWidth: false,
  responsive: true,
  columns:[
     {data: "name", title: "Name"},
     {data: "quote", title: "Pacchetto"},
     {data: "createdAt", title: "Data aggiunta"},
     {data: "updateAt", title: "Aggiornamento"},
     {data: "reward", title: "Guadagno"},
     {data: "payment", title: "Stato"},
  ]
});

reportpage.html

<template name="reportpage">
  	<h1 style="text-align: center">I tuoi Reports</h1>
  	<br/>
  	<div class="center-div">
  	<div class="10u -1u">
		{{> tabular table=TabularTables.Dealers selector=selector class="table table-bordered table-condensed table-responsive"}}
	</div>
	</div>
</template>

How can I use this solution?
— > Change createdAt format

To display:

new moment(dateCreated).format("DD-MM-YYYY")

To insert in collection:

new moment().unix(); //This gives the timestamp you want to save

1 Like

Explain me where to apply?

In your TabularTables.Dealers declaration replace date field by the format you want to display

{
data: “createdAt”,
title: “Date”,
render: function(val, type, doc) {
if (val instanceof Date) {
return moment(val).format(“DD-MM-YYYY”);
} else {
return “NA”;
}
}
},

Thank you very much !, it works great! :slight_smile: