WHERE, Date, and BETWEEN
See original GitHub issueIt appears that there is a bug with how QueryBuilder is handling dates. I only tested with SQLite, but it is possible that this is happening with other implementations.
const start = new Date(date);
start.setHours(0, 0, 0, 0);
const end = new Date(start);
end.setDate(start.getDate() + 1);
const result = await model.createQueryBuilder('q')
// This doesn't work:
// .where('q.createdAt BETWEEN :start AND :end', { start, end })
// This does:
.where(`q.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`)
.getCount();
console.log(result);
return result;
Query in first case:
SELECT COUNT(DISTINCT("q"."id")) as "cnt" FROM "page" "q" WHERE "q"."createdAt" BETWEEN $1 AND $2
[ 2017-11-16T22:00:00.000Z, 2017-11-17T22:00:00.000Z ]
Query in second case:
SELECT COUNT(DISTINCT("q"."id")) as "cnt" FROM "group" "q" WHERE "q"."createdAt" BETWEEN '2017-11-16T22:00:00.000Z' AND '2017-11-17T22:00:00.000Z'
Versions tested: 0.1.5, 0.1.6
Issue Analytics
- State:
- Created 6 years ago
- Reactions:16
- Comments:18 (5 by maintainers)
Top Results From Across the Web
SQL BETWEEN Operator - W3Schools
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin...
Read more >SQL query to select dates between two dates - Stack Overflow
By doing this, you can get all the dates between the given intervals. Save this answer.
Read more >How to Select Data Between Two Dates and Times in SQL ...
SELECT * FROM TABLE_NAME WHERE DATE_TIME_COLUMN BETWEEN 'STARTING_DATE_TIME' AND 'ENDING_DATE_TIME';. Step 1: Create a Database. For this use ...
Read more >SQL Between, MySQL Between Dates, Not Between
We can use multiple between operators too. Its syntax is: SELECT Column(s) FROM table_name WHERE column_name BETWEEN value1 AND value2 AND ...
Read more >Selecting records between two date range query - Plus2net
We can collect records between two date fields of a table by using BETWEEN query. We can use this to get records between...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can add a conditional sentence to the query builder and I use it like this, maybe it will be a useful example for others.