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.