workflows.fit
Back to n8n workflows
n8n templateFreeBy Trey

Get local datetime into Function node using moment.js

![workflow-screenshot](fileId:260) A quick example showing how to get the local date and time into a Function node using moment.js. This relies on the GENERICTIMEZONE environment variable being correctly configured (s...

DevelopmentCore NodesManual TriggerFunctionStart
Loading interactive preview...

Template notes

![workflow-screenshot](fileId:260)

A quick example showing how to get the local date and time into a Function node using moment.js.

This relies on the GENERICTIMEZONE environment variable being correctly configured (see the docs [here](https://docs.n8n.io/reference/configuration.htmltimezone))

NOTE: In order for this to work, you must whitelist the moment library for use by setting the following environment variable:

bash NODEFUNCTIONALLOWEXTERNAL=moment

For convenience, the Function code is as follows:

javascript const moment = require('moment');

let date = moment().tz($env['GENERICTIMEZONE']);