# How can I get current time in a python code node in n8n v2.x?

**URL:** <https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622>\
**Category:** Questions\
**Created:** [January 15, 2026, 11:14pm UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622 "2026-01-15T23:14:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_b\_1](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mike\_b\_1](https://community.n8n.io/u/mike_b_1)\
**Post date:** [January 15, 2026, 11:14pm UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622/1 "2026-01-15T23:14:04Z")

</div>

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.

Oh and this does not work for cloud javascript…

const { DateTime } = require(‘luxon’);  
const utc\_now = DateTime.utc().toISO();

But this does:

const currentTime = new Date().toISOString();

Still want to know why python is being hamstrung to such an extent…

---

<div class="post-metadata">

**Author:** ![Azeezat](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@Azeezat](https://community.n8n.io/u/Azeezat)\
**Post date:** [January 16, 2026, 12:43am UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622/2 "2026-01-16T00:43:07Z")

</div>

You’re not doing anything wrong this is a **documentation + environment mismatch** , and it’s understandably frustrating.

**What’s actually happening:**

1. **`_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.

2. **Python Code node is intentionally sandboxed**  
On n8n (especially cloud):

3. **Cloud JavaScript does NOT allow `require()`**  
So this fails on n8n.cloud:

[azeezatolugbode@gmail.com](mailto:azeezatolugbode@gmail.com)

---

<div class="post-metadata">

**Author:** ![mike\_b\_1](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mike\_b\_1](https://community.n8n.io/u/mike_b_1)\
**Post date:** [January 16, 2026, 12:45am UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622/3 "2026-01-16T00:45:52Z")

</div>

> [@mike\_b\_1](#):
>
> Oh and this does not work for cloud javascript…
> 
> const { DateTime } = require(‘luxon’);  
> const utc\_now = DateTime.utc().toISO();
> 
> But this does:
> 
> const currentTime = new Date().toISOString();

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.

---

<div class="post-metadata">

**Author:** ![Azeezat](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@Azeezat](https://community.n8n.io/u/Azeezat)\
**Post date:** [January 16, 2026, 12:48am UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622/4 "2026-01-16T00:48:27Z")

</div>

Yep, that’s expected on n8n Cloud `require()` isn’t available there, which is why `luxon` fails while `new Date().toISOString()` works.

If you want, I can help you clean this up properly so you’re not fighting the environment:

- Use **n8n-native time helpers** (`$now`) where they make sense

- Pass timestamps into Code nodes cleanly

- Keep the workflow consistent between Cloud and self-hosted

Happy to walk through it with you or help refactor the workflow so time handling “just works.”

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [February 9, 2026, 8:59pm UTC](https://community.n8n.io/t/how-can-i-get-current-time-in-a-python-code-node-in-n8n-v2-x/250622/5 "2026-02-09T20:59:23Z")

</div>

Closed on February 9, 2026, 8:59pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
