I’m trying to use code to reformat the timestamp string (from date picker):
2025-04-03T00:00:00
To the format I need:
2025-04-03
I tried Text Formatter Node: Truncate , 10 tokens (as suggested by Gummie, but doesn’t work). I also tried “Find and Replace”, find “T00:00:00”, replaced with “”, also didn’t work. So I resort to Run Code (Python).
def function(check_in_timepicker):
from datetime import datetime
# Convert the input string to the desired format
check_in_date = datetime.strptime(check_in_timepicker, "%Y-%m-%dT%H:%M:%S").strftime("%Y-%m-%d")
return check_in_date
The error I get is:
" Run Code Failed!
File “/workspace/index.py”, line 6
return check_in_date
IndentationError: unexpected indent"
Hey @tamwendy - There’s an indentation issue in the code as the error suggests, can you share a link to your flow so I can take a closer look at the code format?
Yeah sure - Here’s the before and after of the indentation issue:
Before (with error):
def function(check_in_timepicker):
from datetime import datetime
# Convert the input string to the desired format
check_in_date = datetime.strptime(check_in_timepicker, "%Y-%m-%dT%H:%M:%S").strftime("%Y-%m-%d")
return check_in_date # This line has incorrect indentation (extra space before 'return')
After (fixed):
def function(check_in_timepicker):
from datetime import datetime
# Convert the input string to the desired format
check_in_date = datetime.strptime(check_in_timepicker, "%Y-%m-%dT%H:%M:%S").strftime("%Y-%m-%d")
return check_in_date # This line now has consistent indentation
Python uses indentation to define code blocks, and all lines within the same block must have the same indentation level. In the original code, the first three lines of the function body use three spaces for indentation, but the return statement uses four spaces.
This is a bit puzzling as I get more error after trying to ensure the same space indent within function call. (also please note the UI have a fixed indent for the return line). Thanks for the guidance!
e
[31m Run Code Failed!
Traceback (most recent call last):
File "/workspace/index.py", line 8, in <module>
print('___FUNCTION_OUTPUT___\n' + str(function('')))
File "/workspace/index.py", line 5, in function
check_in_date = datetime.strptime(check_in_timepicker, "%Y-%m-%dT%H:%M:%S").strftime("%Y-%m-%d")
File "/usr/local/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/local/lib/python3.10/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S'
e[0m
Hey! This issue is unrelated to indentation, seems like you’re parsing an empty string as datetime. Make sure you’ve all the inputs setup properly in the flow.
check_in_timepicker is an empty string (''), but you’re trying to parse it using the format "%Y-%m-%dT%H:%M:%S".
I’ve already made sure there are 4 space of indentation before EACH line.
And I would like to report that when using the date picker interface, the date picked would be one day BEFORE the date selected. Say if I picked April 7th, the date April 6th would be shown. Is this a bug? It seems to be doing some kind of auto UTC time adjustment , but it’s not needed from user’s point of view.