Search beetween two dates if the last day is 31 but the month as 30 days


#1

Hi,

I’m making a query to my backend and i want to get back all the purchases done that month.
I make the query like this :

ctx.db.query.userCourses(
{
where: {
AND: [
{ course: { id: args.id } },
{ createdAt_gte: ${date[0]}-${date[1]}-01 },
{ createdAt_lte: ${date[0]}-${date[1]}-31 },
],
},
orderBy: ‘createdAt_ASC’,
},
{ id createdAt course{ id title } user{ id } }
);

but i found that for example this month who has only 30 days the query fails.

I solved it by making the day dynamic too.
My question is if this is the intended behaviour and the server already knows how much days a month has?

Sorry for my bad english,
Thanks


#2

try converting that dates to a ISO Date string


#3

Hi, thank you for the reply,

The query works fine with strings, the “problem” is that i was putting a fixed value for the last day of the month, i was putting 31, and it works like a charm only if the month has 31 days.

If the month only has, for example 30 days, the query don’t work.

I already fixed it, making the last day dynamic, i just make it search until today, instead of search the whole month.

I just want to know if this is the pretended behaviour, if the server keeps track of the the total days any month was.

Thanks for the time