Skip to content
FlowHubFluxonLab
W
General Automationfree

Get local datetime into Function node using moment.js

by Treyadapted from n8n official workflow galleryUpdated Aug 2026
Share Post Share
MaOn clicking 'execute'On clicking 'ex…FuGet Local DatetimeGet Local Datet…1
1/5
STEPS · 1
Run manually by an operator

A quick example showing how to get the local date and time into a Function node using moment.js. This relies on the GENERIC_TIMEZONE environment variable being correctly configured (see the docs here) NOTE: In order for this to work, you must whitelist the moment library for use by setting the following environment variable: NODE_FUNCTION_ALLOW_EXTERNAL=moment For convenience, the Function code is as follows: const moment = require('moment'); let date = moment().tz($env['GENERIC_TIMEZONE']); let year = date.year(); let month = date.month(); // zero-indexed! let day = date.date(); let hour = date.hours(); let minute = date.minutes(); let second = date.seconds(); let millisecond = date.millisecond(); let formatted = date.format('YYYY-MM-DD HH:mm:ss.SSS Z'); return [ { json: { utc: date, year: year, month: month, // zero-indexed!

Tags

n8nreference-only
CategoryGeneral Automation
Triggermanual
Complexitysimple
Nodes2
AddedOct 1, 2020
free

Using the Merge Node - Merge by Key

This is an example of how you can make Merge by Key work. The “Data 1” and “Data 2” nodes simply provide mock data. You can replace them with your own data sources. Then the “Convert Data” nodes are important. They make sure that the different array items are actually different items in n8n. After that, you have then the merge with the merged data.

by mike
free

Write JSON to Disk (Binary)

The “Write Binary File” expects binary data. The JSON data is, however, JSON ;) There should really be a node that allows moving data around between both of them. For now, it can be done with a Function-Node. At least till a proper one is in place. The first node is example data, wich you can customize or replace. The second node named “Make Binary” is the important one with the custom code which makes the data binary and writes it to the correct location.

by mike
free

Webhook returning XML

Receives data from an incoming HTTP Request (set up to use respond to webhook node) Create dummy data Convert JSON to XML which gets returned Respond to Webhook which returns the data and the content type of the data

by Jan Oberhauser