0

Have some problem with "Where transform data from MongoDB"

I want to show date like 10 JUL (for this i must use moment().format(MMM D)) i use momentjs

But in my Mongo i have date in basic format 2015-07-.... ( moment().format())

Where its output

  <td class="submitDate ">{{date}}</td>

I want to do something like this

Template.postJobs.helpers({
  date: function(){
    return this.format("MMM D");
  }
});

QUESTION : is WHERE i can transform date from 2015-07-.... ( moment().format()) to 10 JUL``moment().format(MMM D) and HOW

Anybody help ??

SOLVED:

  <td class="submitDate ">{{formatTime date}}</td>

UI.registerHelper('formatTime', function(context, options) {
  if(context)
    return moment(context).format('MMM D');
});
nl pkr
  • 656
  • 1
  • 11
  • 21

1 Answers1

1

You can create a helper formatter method to do the formatting:

Template.postJobs.helpers({
  formatDate: function(date) {
    return date.format("MMM D");
  }
});

Your html template would pass the date variable into formatDate like this:

<td class="submitDate">{{formatDate this}}</td>
k.chao.0424
  • 1,191
  • 10
  • 11
  • 1
    Hi, if I saw it right from your question, your data source field is called {{date}}. In that case you should call the helper by: {{formatDate date}} – Tom Freudenberg Jul 10 '15 at 21:11