New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WHERE, Date, and BETWEEN #1221
Comments
@voodooattack are you still interested in this issue? If yes, then please check it on |
@pleerock confirming that issue is still present in public async countUnique(after?: Date, before?: Date): Promise<number> {
const filters: ArticleAnalyticsFilter = {
before: before.toISOString() as any,
after: after.toISOString() as any,
// before,
// after
};
const result = await this.getRepository()
.createQueryBuilder()
.select('COUNT(DISTINCT(objectId))', 'unique')
.andWhere('createdAt >= :after')
.andWhere('createdAt < :before')
.setParameters(filters)
.getRawOne();
return result.unique;
} The logging is not useful. Log from using raw
If you can point me to the test that would check this, I can have a go at making a failing test. Thanks in advance. |
I am facing the same issue. Without toISOString() |
@eddieajau I don't think SQL type used by SELECT COUNT(DISTINCT(objectId)) AS "unique" FROM "activity_article" "ArticleAnalytics" WHERE createdAt >= '2018-01-02T00:00:00.000Z' AND createdAt < '2018-01-05T00:00:00.000Z' And see if it doesn't work. If it doesn't work then you need to specify a proper date format. |
Hi @pleerock i think i found one reason: When i use sql query and use the DB format it works. Do you know how i can get the full format time stamp with timezone into Java script. I Tried various ways to get 6 milliseconds digits but at most i get only 3 (as mentioned above). |
If you need high-resolution time you can use process.hrtime() |
import { Between } from 'typeorm';
import { addYears, subYears } from 'date-fns';
// TypeORM Query Operators
export const AfterDate = (date: Date) => Between(date, addYears(date, 100));
export const BeforeDate = (date: Date) => Between(subYears(date, 100), date);
// leter
return Event.find({
where: {
date: AfterDate(new Date()),
},
}); |
Hello !
but i don't like what i've done. i don't feel confident about sql injections |
In JavaScript, you can easily make an
Both Typescript And PostgreSQL know So this works like a chram:
|
*8601 ISO8606 is https://www.iso.org/standard/15911.html - Plastics — Prepregs — Bulk moulding compound (BMC) and dough moulding compound (DMC) — Basis for a specification |
The problem described in this issue is a bug explained in #2286, and not yet fixed. For now, you need to format your dates in the |
if (filter.startDate && filter.endDate) {
query.andWhere('"createdAt" BETWEEN :startDate AND :endDate', { startDate: filter.startDate, endDate: filter.endDate });
} 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. |
Date Between Query is: https://laratuto.com/date-between-query-in-mysql/ |
select * from voucher where voucher date between date1 and date2 and subpartyid = subpartyid |
muchas gracias esa ultima parte del between fue excelsa me ayudo muchisimo en mi trabajo |
Hello there, I'm attempting to compare only time values. example: if 23:57 is BETWEEN 23:55 and 00:00. Any help |
I think you should try comparing numbers instead of dates, the equivalent of 23:57 in milliseconds is between 23:55 and 24:00. Compare the equivalent of hours in milliseconds. |
I used "Between" to query in MongoDB is invalid, and then I continued to try "LessThan", "Not". The filtered data is always empty, but I used tools to query my data. I verified many times. Do you have any suggestions this.robotRepo.find({
order: {
value: 'ASC',
},
where: {
value: Between(5,10),
},
}); |
It 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.
Query in first case:
Query in second case:
Versions tested: 0.1.5, 0.1.6
The text was updated successfully, but these errors were encountered: