Skip to content
Advertisement

Getting A Month’s Worth of Data With KnexJS

I’m trying to get a month’s worth of data using KnexJS, I only have the year and month in the form 20xx-mm.

Here’s my Knex query ..

JavaScript

The issue is, I’m starting at a specific date and going through to the 31’st day, some months have 30 days, some 28 and 29. How do I go about to creating a query that helps me achieve this?

I have tried using SQL’s MONTH function along with Knex’s betweenRaw, but unfortunately, I have only the year and month, and the MONTH function expects a datetime.

Advertisement

Answer

This should solve it

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement