0
Hi, guys. Sorry if my question seems a bit silly, but I’m starting now and doing this query is tying my head in a knot kkk
Next, I’m building a system to manage the company’s vouchers (advances). I already created the login system using express-Session and it’s working fine. Only now I need to create a page that the person sees all their vouchers in the current month. For example: If I entered today (15/08/2020), I would see all the vouchers I requested in August 2020. Do the query looking for the corresponding user id valleys I already got quiet as follows:
const finantialController = {
financeiro: async (req,res)=>{
try {
const vales = await Vales.findAll({
where:
{
userId: req.session.user.id,
},
include: [{model:User}]
})
res.render('finantial/financeiro', {vales: vales})
This piece of code is working beautifully, but I don’t know how to store the current date (maybe I’ll have to do this through datetime) and how to separate the month and year from my database and compare it with datetime. I already have the timestamps in the database, so I would use the "createdAt" column. I have read the documentation, I have tried some ways, I have done a lot of research but unfortunately I have not reached any solution. If you can help me I really appreciate!
Man, thank you so much! You gave me a great idea and I managed to solve doing the following: I created a TODAY variable that gets today’s date, then created a MONTH that gets Today.gethMonth(), then another year call that gets Today.getYear(). Then I created a function (SAMEMONTHANDYEAR) that first filters by month, then by year and returns this value. And then I took that array there VALES and applied a filter with the function. It was right. Thank you very much, man!
– Luan Galvão
Arrange! if you can mark as useful answer I would be happy
– João pedro