Skip to main content
Answer

Relative time in MLHub?

  • October 29, 2024
  • 2 replies
  • 94 views

brahmneufeld
Compass
Forum|alt.badge.img

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

Best answer by Kevin

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

2 replies

Kevin
Employee
Forum|alt.badge.img
  • Employee
  • Answer
  • October 29, 2024

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


brahmneufeld
Compass
Forum|alt.badge.img
  • Author
  • Compass
  • October 29, 2024

That worked perfectly. Thanks for the quick reply 🙂