I have this document example:
{
id: “4041516924230697”,
coll: logs,
ts: Time(“2024-07-22T22:38:59Z”),
Date: “2024/07/22 17:38:53”,
ComputerName: “TI-GILBERTO”,
CPUUsagePercentage: 9.0,
MemAvailablePercentage: 85.58
}
How I can get all documents from collections, filtered by date, example where date.ts from 2024/07/22 to 2024/07/24
I test it but multiple options but I can’t. Reponse is data (empty)
Hi @Gilberto_Tunon and welcome! ![:wave: :wave:](https://emoji.discourse-cdn.com/apple/wave.png?v=12)
Our quickstart demonstrates how to perform a range query. Quick start - Fauna Docs
Can you provide the query that you tried that is not working?
Also, is your Date
field a string, or an actual Date type? Id you want to be able to compare dates, then you should consider converting your date strings into the Date type. https://docs.fauna.com/fauna/current/reference/fql-api/built-in/date/
Thanks. I try to convert my field Date on collection named “logs”, but don’t working. I try like that:
logs.where(Date(.date) >= ‘2024/07/22’)
logs.where(.date >= Date(‘2024/07/22’))
My sample data:
{
id: “404188882909790274”,
coll: logs,
ts: Time(“2024-07-23T08:30:06.610Z”),
Date: “2024/07/23 03:30:02”,
ComputerName: “VEEAM-SRV01”,
CPUUsagePercentage: 0.0,
MemAvailablePercentage: 28.32
}
{
id: “404189826762408000”,
coll: logs,
ts: Time(“2024-07-23T08:45:06.740Z”),
Date: “2024/07/24 03:45:02”,
ComputerName: “VEEAM-SRV01”,
CPUUsagePercentage: 0.0,
MemAvailablePercentage: 28.34
}
In both of your examples, it looks like you are still trying to compare Date
types with strings. Make sure that you actually convert the strings properly to compare dates. Additionally, what you have stored in your documents is an inappropriate format for constructing Date
types. You must provide an appropriate ISO date string, which may NOT include the time. Time
is a different type and must also be properly formatted.
Our documentation on using the Date type can be found here: Date() - Fauna Docs
It also looks like the field that is stored is .Date
, not .date
. Properties are case-sensitive, so watch out for that. If you try to select .date
when there is no such field, it will likely resolve to null
which will always end up failing the comparison and not produce any errors.
![image](https://global.discourse-cdn.com/business4/uploads/fauna1/original/2X/4/4d34fdccaccbdc5f07aa49897c3173164e65b5f2.png)
Thanks so much. I will check it.