Skip to main content

Hi team, 

I’m working through an example based on this Github example: https://github.com/TrendMinerCS/notebooks/blob/main/MLHub/Get%20Interpolated%20Data.ipynb

In the 4th notebook module there is this snippet of code:

start = "2022-04-17T07:00:02.000Z"end = "2022-04-19T07:10:02.000Z"

How could this be changed to relative time, e.g. start=”-7d” and end=”*” (to use PI’s time notation)?

Hi there - great question!

You can use the below code:

# Import datetime
from datetime import datetime
from datetime import timedelta

# 7-day pull
# Start and end timestamps to pull timeseries data; format yyyy-MM-ddTHH:mm:ss.000Z
start = datetime.now() - timedelta(days=7)
start = start.strftime("%Y-%m-%dT%H:%M:%S.000Z")
end = datetime.now()
end = end.strftime("%Y-%m-%dT%H:%M:%S.000Z")

Hope this helps!

KL


That worked perfectly. Thanks for the quick reply 🙂


Reply