admin管理员组文章数量:1405549
TypeORM with a SQLite DB
I am using querybuilder and I would like to bring back data that matches a date I am sending in this format "2024-12-11". The field is a datetime field and the date looks like this when in the db "2024-12-11 00:00:00.000".
If I compare what is there with new Date("2024-12-11") it works fine but I would rather just be comparing the date than datetime.
This is what my code looks like:
.andWhere("logs.log_date = :log_date", {log_date: new Date("2024-12-11")})
Thanks
TypeORM with a SQLite DB
I am using querybuilder and I would like to bring back data that matches a date I am sending in this format "2024-12-11". The field is a datetime field and the date looks like this when in the db "2024-12-11 00:00:00.000".
If I compare what is there with new Date("2024-12-11") it works fine but I would rather just be comparing the date than datetime.
This is what my code looks like:
.andWhere("logs.log_date = :log_date", {log_date: new Date("2024-12-11")})
Thanks
Share asked Mar 7 at 20:02 JustCoderJustCoder 374 silver badges10 bronze badges1 Answer
Reset to default 1import { getRepository } from 'typeorm';
import { Log } from './entities/Log';
async function getLogsByDate(dateString: string) {
return getRepository(Log)
.createQueryBuilder('logs')
.where('DATE(logs.log_date) = :log_date', { log_date: dateString })
.getMany();
}
Use DATE(logs.log_date) = :log_date
in your TypeORM query builder to compare dates in SQLite.
本文标签: javascriptTypeORM compare datetime field to date (ignoring time)Stack Overflow
版权声明:本文标题:javascript - TypeORM compare datetime field to date (ignoring time) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744911048a2631915.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论