I need to display a date from database in the format 'mm-dd-yyyy'. As its saved in ISO format in mongodb
how can I convert it in the template ? Here is my code.
Template.templatename.vname = function () { return Posts.find(); }
And in template
{{#each vname}} {{ date }} {{/each}}
Now its getting displayed like Tue Feb 04 2014 00:00:00 GMT+0530 (IST)
I need to show it as mm-dd-yyyy
Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.
yyyy-MM-dd — Example: 2013-06-23.
In "Control Panel\All Control Panel Items\Region and Language", on the "Formats" tab, click "Additional settings..." button. Visual Studio 2008 debugger formats dates using "Short date:" from the "Date" tab of "Customize Format".
You may want to create a global helper like:
Template.registerHelper('formatDate', function(date) { return moment(date).format('MM-DD-YYYY'); });
Then you can use it like:
{{#each vname}} {{formatDate date}} {{/each}}
This solution depends on moment which is a handy date manipulation library. If you prefer to produce the string without using moment, there are a number of answers for this including this one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With