<@ULVA73B9P> I have this automation body I want fl...
# ask-marvin
a
@Marvin I have this automation body I want flow_run timestamp till seconds only Flow run {{ flow.name }}/{{ flow_run.name }} entered state
{{ flow_run.state.name }}
at {{ flow_run.state.timestamp }}.
m
To help you format the
flow_run.state.timestamp
to display only up to seconds, I'll need to know which version of Prefect you're using, as syntax can vary between versions. Could you please confirm your Prefect version? If you're not sure, let me know, and I'll guide you on how to find this information.
a
@Marvin I am using 2.20
m
To format the
flow_run.state.timestamp
to display only up to seconds in Prefect 2.x, you can manipulate the timestamp as a string to get the desired format. You would typically use Python's datetime formatting for such a task. Here's a general approach: 1. You can access the timestamp and convert it to a Python datetime object. 2. Format it to display only up to seconds. Since you are using placeholders in a string, I'll illustrate how to achieve this in a hypothetical Python context first, and then you can incorporate it into your template:
Copy code
python
from datetime import datetime

# Suppose this is your flow_run.state.timestamp
timestamp_str = "2023-10-06T14:48:00.123456Z"

# Convert it to a datetime object
timestamp_dt = datetime.fromisoformat(timestamp_str.replace("Z", "+00:00"))

# Format it to show only up to seconds
formatted_timestamp = timestamp_dt.strftime("%Y-%m-%d %H:%M:%S")

print(formatted_timestamp)  # Outputs: 2023-10-06 14:48:00
For your template, you would do something similar where you access the
flow_run.state.timestamp
, parse it into a datetime object, and then reformat it. For more details and options to handle similar cases, you can refer to the Prefect logging guide or the flow run automation documentation. These resources might offer deeper integration techniques for customizing outputs.