Back

Help me i want to get all data of one day before , what i did wrong in my code ?

  • 0
  • Web
Shubham
6 Mar, 2024, 14:27
TypeScript
    const oneDayAgo = new Date();
    oneDayAgo.setDate(oneDayAgo.getDate() - 1);

const result=await database.listDocuments(databaseid, collectionId,[
              Query.limit(50),
             Query.orderDesc("$createdAt"),
             Query.greaterThan("$createdAt",oneDayAgo),
             Query.lessThan("$createdAt",today)
  ])
TL;DR
Developers are trying to fetch data from one day before, but the code is resulting in a server error. The issue may be with how the date is being handled. One suggestion is to use .toISOString(), and another idea is to check if the code works without queries.
Faye
6 Mar, 2024, 14:42

Please explain more what your issue is, what errors do you have? Is there anything else we need to know?

Shubham
6 Mar, 2024, 14:45

it says server error

Faye
6 Mar, 2024, 14:45

So a 500 I'm guessing. Can you try without queries and see if that works?

Shubham
6 Mar, 2024, 14:51

yes its not working after Query.greaterThan("$createdAt",oneDayAgo)

Faye
6 Mar, 2024, 14:54

what does oneDayAgo variable result in?

Shubham
6 Mar, 2024, 14:57

its return a date

Faye
6 Mar, 2024, 14:59

try using .toISOString()

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more