0
I would like to format a date that is being loaded from the database with Sequelize. I’m blogging and I need to get the article creation date
My route:
app.get("/", (req,res) =>{
Article.findAll({
order:[
['id','DESC']
],
limit:6
}).then(articles =>{
Category.findAll().then(categories =>{
res.render("index.ejs", {articles:articles, categories:categories})
})
})
})
In my "INDEX.EJS", I am foreach the articles:
<% articles.forEach(articles => {%>
<div class="card">
<div class="card-header">
<h2><%= articles.title%></h2>
</div>
<br>
<div class="card-body" >
<%- articles.img%>
<h5><%= articles.subtitle%></h5>
<h5 id="displayMoment"><%= articles.createdAt%></h5>
<a href="/<%= articles.slug%>" class="btn btn-success">Ler artigo</a>
</div>
</div>
<br>
<% })%>
<script type="text/javascript">
(function()
{
var NowMoment = moment().format('LLL');
var eDisplayMoment = document.getElementById('displayMoment');
eDisplayMoment.innerHTML = NowMoment;
})();
</script>
It is returning the current date, not the creation date of the articles. I would more like to know how you pass this createdAt variable inside the Moment()
I already tried to do this, but it returns as invalid date
– AliBabaMc