How to filter date using query entity?

Hi All,

I have a scenario where i need to filter the data from db based on the date. Filter values will be something like below.

Today

Yesterday

Last 7 days

Last 30 days

FYI,

In Db,  date column is stored in date time format. I’m able to achieve it if the date is stored in date formate rather that date time.  

 

Can an someone suggest me how to achieve the filtering thing from db based on the date when db value is date time?

 

Thanks in advance

 

  Discussion posts and replies are publicly visible

Parents
  • Conversion from a Date object to a Date and Time object will specify the year, month and day and set the time to be its morning's midnight. However, it will be in GMT time so in Australia the rule todatetime(today()) will give something like "14/01/2019 11:00am". This is an easy workaround by calling the gmt() function on it. As such gmt(todatetime(today())) now gives "14/01/2019 00:00am". However, there is a bug with the 'today' rule which will only give you GMT's today rather than the local today. I'll skip the explanation this time: gmt(todate(local(now()))) will get the correct date and then find the start of that date.

    Now we have the beginning of today, how do we get a range across all of the day? Well we can take advantage of the fact that midnight tomorrow marks the end of today. As such, we just add a day onto or previous result: gmt(todate(local(now()))) + day().

    We can use this same logic to shift this to previous days or extend the range. To change how many days to shift it, use multiplication and to go backwards, use minus. For instance, the start of day from one week ago would be: gmt(todate(local(now()))) - day() * 7.

    Altogether, we ended up using the following logic for our date ranges filters. In particular, I will show you our 'Last Week' (not including today):

    with(
    local!today: gmt(todate(local(now()))),
    a!queryFilter(
      field: "dateTime",
      operator: "between",
      value: {local!today - (day() * 7), local!today}
    )
    )
  • Thank you for your suggestion Tom. It worked :)
Reply Children
No Data