Skip to main content

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)?

Thanks for help.

Definitely seems possible via a code step:

https://www.programiz.com/python-programming/datetime/current-time


@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:
93cc74426b1cf4cbb31503e337eba180.png

Which you could then select in subsequent steps:

73f93454d49812245a8cf23c6674ea14.png

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"

return {

    'Date': date_only

}

Like so:
00acad0b1e42d84a9ce76c6d9654c78b.png

You can find out more about the different date formatting options available in Python here: strftime() and strptime() Format Codes :slight_smile: