I was told by the AI documentation that I could get current time in a python code node with str(_now) only to be told at run time that _now does not exist. And we cannot import datetime. So I have to add a javascript node before that to get current time? come on.
You’re not doing anything wrong this is a documentation + environment mismatch, and it’s understandably frustrating.
What’s actually happening:
_now does not exist in the Python Code node
That variable is only available in expression context, not inside Code nodes. The docs blur this distinction.
Python Code node is intentionally sandboxed
On n8n (especially cloud):
You cannot import datetime
You cannot rely on system time
This is by design for security and determinism.
Cloud JavaScript does NOT allow require()
So this fails on n8n.cloud:
The documentation seems to be lonely and take me down a path (with it) that needs undoing. The alternate to luxon does work. Not sure why the documentation did supply that answer rather than the luxon since it works likely for all instances… self-hosted or cloud.