How to get today's date (Not via zap_meta_human_now)
I know there is {{zap_meta_human_now}} for adding the date and time the zap runs.
But I am looking for something like “Get Today’s Date” at the beginning of a new Zap to compare this date with a recently added date with {{zap_meta_human_now}} in a certain field.
Is this possible with a Javascript or Python script (get current date)?
@AndrewJDavison_Luhhu That’s perfect! Thanks a lot. The one problem is, that the output of the current time is wrong (it’s not the correct timezone). Is it possible to choose the correct timezone or just add the missing value to the hour? I.e. 09+2 (2 = the difference to the local timezone).
from datetime import datetime
# datetime object containing current date and time now = datetime.now()
print("now =", now)
# YY-MM-DD HH-mm dt_string = now.strftime("%Y-%m-%d_%H-%M") print("date and time =", dt_string)
I do have a problem now with the output of this Python script:
from datetime import datetime
# datetime object containing current date and time now = datetime.now()
print("now =", now)
# YY-MM-DD HH-mm dt_string = now.strftime("%Y-%m-%d_%H-%M") print("date and time =", dt_string)
The test did work and I got the correct result, but when I want to add the result in a later step of the Zap the output is missing: Please return output or return early.
I am sorry, but I do not know Python so well. What does this mean?
Thanks for help.
@michael291
Unless you are doing the comparison in a code step, I don’t see how it would be different than just using a formatter with {{zap_meta_human_now}}
If you just want the date and not the time field you can specify that in the formatter
Thanks @GetUWired you’re right. Didn’t know I can convert the timezone too.
Hey all! It seems like @michael291 may have ended up using a Formatter step and {{zap_meta_human_now}} to output the date and time a Zap runs as GetUWired suggested. But I thought I’d follow up here to confirm that it is possible to output the date and time a Zap runs using Python.
For example this Python code:
# imports the datetime module
from datetime import datetime
# Gets the current date and time
time_now = datetime.now()
#converts the default date time into YYYY-MM-DD HH:MM format
date_time = time_now.strftime("%Y-%m-%d %H:%M")
#outputs the current date and time in a field called "Date and Time"
return {
'Date and Time': date_time
}
would create a field called Date and Time with the current date and time:
Which you could then select in subsequent steps:
And if you wanted to output just the date you could adjust the code so that only the date is output:
# imports the datetime module
from datetime import datetime
# Gets the current date and time
time_now = datetime.now()
#converts the default date time into YYYY-MM-DD format
date_only = time_now.strftime("%Y-%m-%d")
#outputs the current date and time in a field called "Date"