Change createdAt format

I want to display {{name}} - {{createdAt}}, but i get the format from database pop - Thu Aug 25 2016 20:42:00 GMT+0300 (GTB Summer Time)

How do i change the format to something more friendly like yyyy-MM-dd

Collection:

Cvs = new Mongo.Collection('cvs');
...
    createdAt: {
        type: Date,

I tried like in this example

Template.registerHelper("prettifyDate", function(timestamp){
    return new Date(timestamp).toString('yyyy-MM-dd')
})

{{prettifyDate createdAt}}

, but nothing is changed.

My strategy:

import { moment } from 'meteor/momentjs:moment';

Template.registerHelper('formatDate', function(date, format) {
  // Use moment.js formatting to return a date we like (http://momentjs.com/)
  // Example: {{formatDate createdAt 'MM/DD/YYYY'}}

  return moment(new Date(date)).format(format);
});

1 Like

Thanks @vigorwebsolutions !

1 Like