cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Purge Stream from Beginning of Time till Certain Date

ague
13-Aquamarine

Purge Stream from Beginning of Time till Certain Date

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

ACCEPTED SOLUTION

Accepted Solutions
Rajesh_Sayana
13-Aquamarine
(To:ague)

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
})

View solution in original post

4 REPLIES 4
Rajesh_Sayana
13-Aquamarine
(To:ague)

Please refer to the following document for best practices on purging data: Purging Data: Best Practices 

 

ague
13-Aquamarine
(To:Rajesh_Sayana)

So, the relevant points from this article that I'm taking are this (emphasis mine):

 

  • For each, if no start date is given, all values will be purged (starting with the 1970s epoch, see KCS Article CS271231 to purge older values)
  • If no end date is given, all properties up until the runtime of the service will be purged

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. 

Rajesh_Sayana
13-Aquamarine
(To:ague)

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
})
ague
13-Aquamarine
(To:Rajesh_Sayana)

Thank you! I will give this a try! 

Announcements


Top Tags