Back

Query Appwrite

  • 0
  • Databases
  • Web
Morel
12 Dec, 2024, 14:33

Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?

TL;DR
The developer is querying the $createdAt column using a string in the format "YYYY-MM". The solution is to create variables for the start and end of the month using the provided date string. Then, include a query to filter records between these dates using `sdk.Query.between('$createdAt', startOfMonth, endOfMonthISO)`.
Morel
12 Dec, 2024, 14:35

const date_time = "2024-11"; const batchs = await databases.listDocuments( process.env.APPWRITE_DATABASE_ID, process.env.APPWRITE_COLLECTION_ID, [ ? ] );

Morel
12 Dec, 2024, 14:41

[SOLVED]

TypeScript
   const startOfMonth = "${date_time}-01T00:00:00.000Z";
    const endOfMonth = new Date("${date_time}-01T00:00:00.000Z");
    endOfMonth.setMonth(endOfMonth.getMonth() + 1);
    endOfMonth.setDate(0);
    const endOfMonthISO = endOfMonth.toISOString();
    query.push(sdk.Query.between('$createdAt', startOfMonth, endOfMonthISO));
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