<@ULVA73B9P> how to convert from type that is retu...
# ask-marvin
p
@Marvin how to convert from type that is returned by flow_run.get_scheduled_start_time() to normal python datetime?
m
thought for 53.1 seconds
I notice there might be a misunderstanding in your question. In Prefect 3.x,
scheduled_start_time
is actually an attribute, not a method, so you would access it as
flow_run.scheduled_start_time
rather than calling
flow_run.get_scheduled_start_time()
. The
scheduled_start_time
is typically returned as an ISO-formatted string. To convert it to a Python datetime object, you can use one of these approaches:
Copy code
python
from datetime import datetime
from dateutil import parser

# Option 1: Using datetime.fromisoformat()
datetime_obj = datetime.fromisoformat(flow_run.scheduled_start_time)

# Option 2: Using dateutil parser (more flexible)
datetime_obj = parser.parse(flow_run.scheduled_start_time)
The
dateutil.parser
approach is more flexible and can handle various datetime string formats, while
datetime.fromisoformat()
is built into Python's standard library but expects specifically formatted ISO strings. If you're seeing a different return type or getting any errors with these conversions, please let me know what type you're actually getting (you can check with
print(type(flow_run.scheduled_start_time))
) and I can provide more specific guidance.