{"_id":"5937b2388e8d9b002f1df284","category":{"_id":"5937b2388e8d9b002f1df272","version":"5937b2378e8d9b002f1df26e","project":"542fe92a5eceb608003fddc8","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-04T12:45:40.548Z","from_sync":false,"order":3,"slug":"helper-reference","title":"Helper Reference"},"project":"542fe92a5eceb608003fddc8","user":"542c5cfcddd3190e00228849","parentDoc":null,"version":{"_id":"5937b2378e8d9b002f1df26e","project":"542fe92a5eceb608003fddc8","__v":1,"createdAt":"2017-06-07T07:58:47.936Z","releaseDate":"2017-06-07T07:58:47.936Z","categories":["5937b2388e8d9b002f1df26f","5937b2388e8d9b002f1df270","5937b2388e8d9b002f1df271","5937b2388e8d9b002f1df272","5937b2388e8d9b002f1df273","5937b2388e8d9b002f1df274"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-10-04T19:31:22.094Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":28,"body":"[block:html]\n{\n  \"html\": \"<div class=\\\"github-deeplinks\\\">\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/date.js\\\"><i class=\\\"fa fa-github-alt fa-right\\\"></i>Source</a>\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/test/unit/server_helpers/date_spec.js\\\"><i class=\\\"fa fa-check-square-o fa-right\\\"></i>Tests</a>\\n</div>\"\n}\n[/block]\nUsage: `{{date dateToFormat format=\"formatString\"}}`\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Type\",\n    \"h-1\": \"Parameters\",\n    \"h-2\": \"Attributes\",\n    \"0-0\": \"[Output](/docs/helpers#section-output), [Formatting](/docs/helpers#section-formatting), [Ghost](/docs/helpers#section-ghost)\",\n    \"0-1\": \"date to format (date, default `published_at` it available, or 'now')\",\n    \"0-2\": \"*  `format` (date format, default “MMM Do, YYYY”)\\n*  `timeago` (boolean)\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n### Description\n\n`{{date}}` is a formatting helper for outputting dates in various format. You can either pass it a date and a format string to be used to output the date like so:\n\n```\n// outputs something like 'July 11, 2016'\n{{date published_at format=\"MMMM DD, YYYY\"}}\n```\n\nOr you can pass it a date and the timeago flag:\n\n```\n// outputs something like '5 mins ago'\n{{date published_at timeago=\"true\"}}\n```\n\nIf you call `{{date}}` without a format, it will default to “MMM Do, YYYY”.\n\nIf you call `{{date}}` without telling it which date to display, it will default to one of two things:\n\n1. If there is a `published_at` property available (i.e. you're inside a post object) it will use that\n2. Otherwise, it will default to the current date\n\n\n`date` uses [moment.js](http://momentjs.com/) for formatting dates. See their [documentation](http://momentjs.com/docs/#/parsing/string-format/) for a full explanation of all the different format strings that can be used.\n\n### Example Code\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<main role=\\\"main\\\">\\n  {{#foreach posts}}  \\n    <h2><a href=\\\"{{url}}\\\">{{title}}</a></h2>\\n  \\n   <p>{{excerpt words=\\\"26\\\"}}</p>\\n  \\n    {{!-- Here `published_at` is set, so this will show the article date --}}\\n    <time datetime=\\\"{{date format=\\\"YYYY-MM-DD\\\"}}\\\">{{date format=\\\"DD MMMM YYYY\\\"}}</time>\\n  {{/foreach}}\\n</main>  \\n<footer>\\n  {{!-- Here there is no `published_at` so this will show the current year --}}\\n  <p class=\\\"small\\\">&copy; {{date format=\\\"YYYY\\\"}}</p>\\n</footer>  \\n\",\n      \"language\": \"html\",\n      \"name\": \"index.hbs\"\n    }\n  ]\n}\n[/block]","excerpt":"`{{date}}` Helper - Format a date using moment.js","slug":"date","type":"basic","title":"date"}

date

`{{date}}` Helper - Format a date using moment.js

[block:html] { "html": "<div class=\"github-deeplinks\">\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/date.js\"><i class=\"fa fa-github-alt fa-right\"></i>Source</a>\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/test/unit/server_helpers/date_spec.js\"><i class=\"fa fa-check-square-o fa-right\"></i>Tests</a>\n</div>" } [/block] Usage: `{{date dateToFormat format="formatString"}}` [block:parameters] { "data": { "h-0": "Type", "h-1": "Parameters", "h-2": "Attributes", "0-0": "[Output](/docs/helpers#section-output), [Formatting](/docs/helpers#section-formatting), [Ghost](/docs/helpers#section-ghost)", "0-1": "date to format (date, default `published_at` it available, or 'now')", "0-2": "* `format` (date format, default “MMM Do, YYYY”)\n* `timeago` (boolean)" }, "cols": 3, "rows": 1 } [/block] ### Description `{{date}}` is a formatting helper for outputting dates in various format. You can either pass it a date and a format string to be used to output the date like so: ``` // outputs something like 'July 11, 2016' {{date published_at format="MMMM DD, YYYY"}} ``` Or you can pass it a date and the timeago flag: ``` // outputs something like '5 mins ago' {{date published_at timeago="true"}} ``` If you call `{{date}}` without a format, it will default to “MMM Do, YYYY”. If you call `{{date}}` without telling it which date to display, it will default to one of two things: 1. If there is a `published_at` property available (i.e. you're inside a post object) it will use that 2. Otherwise, it will default to the current date `date` uses [moment.js](http://momentjs.com/) for formatting dates. See their [documentation](http://momentjs.com/docs/#/parsing/string-format/) for a full explanation of all the different format strings that can be used. ### Example Code [block:code] { "codes": [ { "code": "<main role=\"main\">\n {{#foreach posts}} \n <h2><a href=\"{{url}}\">{{title}}</a></h2>\n \n <p>{{excerpt words=\"26\"}}</p>\n \n {{!-- Here `published_at` is set, so this will show the article date --}}\n <time datetime=\"{{date format=\"YYYY-MM-DD\"}}\">{{date format=\"DD MMMM YYYY\"}}</time>\n {{/foreach}}\n</main> \n<footer>\n {{!-- Here there is no `published_at` so this will show the current year --}}\n <p class=\"small\">&copy; {{date format=\"YYYY\"}}</p>\n</footer> \n", "language": "html", "name": "index.hbs" } ] } [/block]