Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
I have a stream that I would like to purge of any data which is older than 7 days old. My thought is to attempt something like this (below), where my startDate is undefined and my endDate equals seven days ago (DateTime format).
Things["MY_STREAM"].PurgeStreamEntries({
endDate: sevenDaysAgo,
immediate: true,
startDate: undefined
});
Will this work? I'm worried that if the startDate is undefined, it'll start from the newest entry of the stream, rather than the oldest entry.
TWX v. 8.4.1
Solved! Go to Solution.
You may try this out:
var sDate = '0000-01-01T00:00:00.000-00:00'; // This will allow purging from the dawn of time, and not just the 1970s epoch var nowDate = Date.now(); var eDate = new Date(nowDate - 7*86400000); // Multiply by the milliseconds in a day to convert days to ms // 7 here specifies the number of days of data you would want to keep Things["MY_STREAM"].PurgeStreamEntries({ endDate: eDate, immediate: true, startDate: sDate })
Please refer to the following document for best practices on purging data: Purging Data: Best Practices
So, the relevant points from this article that I'm taking are this (emphasis mine):
So my options are to just purge 100% of my data OR purge everything from the start of time until the time my service ran?
What I want to do is run a service now (on June 6th, for example) that purges from the beginning of time until March 30th (for example). Is this possible? I can find nothing in the article which addresses this, unless the points I copied, above, are trying to say that and are just extremely poorly worded.
You may try this out:
var sDate = '0000-01-01T00:00:00.000-00:00'; // This will allow purging from the dawn of time, and not just the 1970s epoch var nowDate = Date.now(); var eDate = new Date(nowDate - 7*86400000); // Multiply by the milliseconds in a day to convert days to ms // 7 here specifies the number of days of data you would want to keep Things["MY_STREAM"].PurgeStreamEntries({ endDate: eDate, immediate: true, startDate: sDate })
Thank you! I will give this a try!