Sysdate -3 months on a fetch

#1

Can someone give an example of how I can use time to limit my query to the last 3 months so I am not looking to the beginning of time.

c3Grid(.fetch({limit: 10, asof:Date.now()-606024*70 }));

0 Likes

#2

I’m not sure you want to use asOf in your fetch spec. asOf applies to TimedValueHistory or TimedRelations, and will only return the values that were effective at that time.

For generic, time-based fetches, you can add them to your filter. For example, to fetch SmartBulbs that “started” in the past 90 days:

var ninetyDaysMS = 90*24*3600*1000;
var dte = Date().now().addMilliseconds(-1 * ninetyDaysMS)
var resp = SmartBulb.fetch({filter:"start > dateTime('" + dte.serialize() + "')"});
0 Likes