Back

how can query on a two datetime attribute?

  • 0
  • Self Hosted
  • Databases
  • Web
Rovar2000
28 Feb, 2024, 05:12
TypeScript
  if(options?.from && options?.to) {
      console.log(options?.from, options?.to);
      
      query.push(
        Query.greaterThanEqual("startDate", options.from),
        Query.lessThanEqual("endDate", options.to)
        );
    }

i apply this query but the result it's always empty how can i apply a query on a date?

TL;DR
Developers wanted to query on two datetime attributes and found a solution. They realized they needed to calculate UTC time for better measurement.
Steven
28 Feb, 2024, 05:39

What is from and to? They should be iso formatted strings

Rovar2000
28 Feb, 2024, 05:41
TypeScript
const filterByDate = async function () {
    console.log("Calendar Date", calendarDate[0].$d, calendarDate[1].$d);
    
    outOfCityOrderListOptions.startDate = calendarDate[0].$d;
    outOfCityOrderListOptions.startDate.setUTCHours(0, 0, 0, 0);
    outOfCityOrderListOptions.endDate = calendarDate[1].$d;
    outOfCityOrderListOptions.endDate.setUTCHours(23, 59, 59, 999);
    const result = (await outOfCityOrderListStore.getAll({
      from: outOfCityOrderListOptions.startDate.toISOString(),
      to: outOfCityOrderListOptions.endDate.toISOString(),
    }) as Store<OutofCityOrderListDto>);
    
    console.log("Result",result);
    
    if(result.data.length === 0 && result.total === 0){
      await outOfCityOrderListStore.create({
        startDate: outOfCityOrderListOptions.startDate,
        endDate: outOfCityOrderListOptions.endDate,
        outofCityOrderIds:[]
      })
    }
  };

i converted them to ISOFormat but sometimes it doesn't work sadly

Steven
28 Feb, 2024, 05:50

Uhh... Not sure what all that set UTC hours stuff is...assuming you have a date object, all you need to do is call date.toISOString()

Rovar2000
29 Feb, 2024, 07:00

thank you that worked for me like that. i thought i should calculate the utc time too for good measurements.

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