from datetime import datetime
maintDate = ‘’
def main(event):
try:
input_fields = event.get(‘inputFields’)
# Get the maintenance start and end dates
maint_start_date = input_fields.get(‘maint_start_date’)
maint_end_date = input_fields.get(‘maint_end_date’)
# Check if the dates are not None and are valid datetime objects
if maint_start_date is None or maint_end_date is None:
raise ValueError(“Maintenance start date or end date is missing.”)
# Assuming the dates are in string format, convert them to datetime objects
maint_start_date = datetime.strptime(maint_start_date, ‘%Y-%m-%d’)
maint_end_date = datetime.strptime(maint_end_date, ‘%Y-%m-%d’)
# Format the dates as strings
maintDate = maint_start_date.strftime(‘%Y-%m-%d’) + " to " + maint_end_date.strftime(‘%Y-%m-%d’)
return {
“outputFields”: {
“maintDate”: maint_date
}
}
except Exception as e:
return {
“error”: str(e)
}
With this above code, in the Data Outputs when I test the flow it gives me error maintDate is not defined in code.
