Format Dates in n8n Without Errors (Complete Guide)

Working with date fields in n8n can get tricky, especially when you're connecting different systems that expect dates in various formats. Whether you’re sending a timestamp to Google Sheets, formatting a human-readable date for an email, or converting time zones for scheduling, knowing how to format date fields in n8n is essential. This complete guide will walk you through the correct way to handle, parse, and reformat dates in n8n without errors.

Why Date Formatting Matters in n8n

Dates may seem simple at first glance, but different applications use unique date formats. A US-based service may expect MM/DD/YYYY, while another API could reject anything that’s not ISO 8601 (YYYY-MM-DDTHH:mm:ssZ).

If you don't format date fields properly:

  • APIs might reject your request
  • Your automation could produce incorrect results
  • Data may appear confusing in reports or logs

Understanding how to format date fields in n8n ensures smooth integrations and accurate data flow across your workflows.

Built-in n8n Tools for Manipulating Dates

n8n provides the Set, Function, and FunctionItem nodes to format dates. Recently, improvements to the Set node allow basic date operations without writing code. Still, using JavaScript within Function or FunctionItem gives you more control.

Let’s explore each in practical steps.

Formatting Dates Using the Set Node

Basic Example: Format Date to MM-DD-YYYY

Suppose you receive a timestamp like 2024-06-10T08:30:00.000Z, and you want it in MM-DD-YYYY format.

Step-by-step:

  1. Add the Set node after your data source node.
  2. In the Set node:
    • Click Add ValueExpression.
    • For the name, enter something like formattedDate.
    • Use this expression:
      new Date($json["dateField"]).toLocaleDateString("en-US")
      

      This converts an ISO timestamp to a readable US date format.

Tip:

Make sure you replace "dateField" with the actual key that holds your original date value.

Add Time Formatting:

To include time:

new Date($json["dateField"]).toLocaleString("en-US", { timeZone: "UTC" })

This returns something like: 6/10/2024, 8:30:00 AM

Using Function Node for Advanced Date Formatting

For custom formats — like YYYY/MM/DD or adding offset logic — the Function node is more powerful.

Use Case: Format ISO Date to Custom Format

Let’s say your API requires this format: 2024/06/10.

Steps:

  1. Add a Function node.

  2. Use this script:

    const date = new Date($json["dateField"]);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return [{ formattedDate: `${year}/${month}/${day}` }];
    
  3. The new field formattedDate will hold your correctly formatted date.

Convert Timezones in n8n

By default, JavaScript uses the server's timezone unless specified. To control timezones, consider using the external Luxon library by installing a community package, but many basic cases can be handled through toLocaleString() with timeZone configuration.

Example: Convert to EST

new Date($json["dateField"]).toLocaleString("en-US", { timeZone: "America/New_York" })

This is helpful for scheduling, reporting, or when interfacing with users in different regions.

Formatting Date & Time Together

To clearly see how different formats behave, consider this sample comparison table:

Format Type JavaScript Expression Output Example
MM/DD/YYYY toLocaleDateString("en-US") 06/10/2024
ISO String new Date().toISOString() 2024-06-10T08:30:00.000Z
Custom YYYY/MM/DD Custom split using getFullYear()/getMonth()/getDate() methods 2024/06/10
Date and Time (EST) toLocaleString("en-US", { timeZone: "America/New_York" }) 6/10/2024, 4:30:00 AM

You can copy and adapt these for emails, Slack messages, Sheets inputs, and REST API payloads.

Real-World Use Case: Google Sheets Formatting

Let’s say you're logging form submissions in Google Sheets, but the spreadsheet expects the date in DD-MM-YYYY.

  1. Extract the submission timestamp.

  2. Use a Function node:

    const rawDate = new Date($json["timestamp"]);
    const day = String(rawDate.getDate()).padStart(2, '0');
    const month = String(rawDate.getMonth() + 1).padStart(2, '0');
    const year = rawDate.getFullYear();
    return [{ formattedDate: `${day}-${month}-${year}` }];
    
  3. Use the formattedDate in your Google Sheets node as the target column value.

Want to learn more about Google integrations? Check out this n8n Google Apps integration guide.

Trouble-Shooting Common Date Formatting Errors

Formatting issues in n8n usually fall into these common pitfalls:

  • Input is not a valid date string: Always ensure your input follows ISO or recognized JS date string formats.
  • Timezones shift by a few hours: Use toLocaleString() with explicit timeZone.
  • Output appears "Invalid Date": Check for undefined or null values in inputs.

Here’s a pro tip on catching errors and recovering workflows automatically to prevent failure due to formatting glitches.

Internal Best Practices for Dates in n8n

  • Always convert to ISO before processing between tools unless otherwise specified.
  • When dealing with APIs, use toISOString() unless the API doc says otherwise.
  • Use UTC timestamps for consistency, then format for display or regional output.

FAQ

How do I change the date format in n8n to DD/MM/YYYY?

Use a Function node with JavaScript:

const d = new Date($json["date"]);
return [{
  formattedDate: `${String(d.getDate()).padStart(2, '0')}/${String(d.getMonth()+1).padStart(2, '0')}/${d.getFullYear()}`
}];

Can I format dates in n8n without JavaScript?

Yes, use the Set node with expressions and toLocaleDateString(). For complex formats, JavaScript is recommended.

Does n8n handle timezone conversions natively?

Through JavaScript’s built-in toLocaleString() and specifying the timeZone option, yes. For more advanced cases, you can install a library like Luxon.

Why am I getting “Invalid Date” in my Set node?

This usually happens if the input date is undefined, contains extra spaces, or is not in a recognized format. Check your incoming data carefully.

Can I use formatted dates in Slack or Emails?

Absolutely. Format your date in the Function or Set node, then pass that field into your Slack, Email, or other messaging node. You can combine it with text like:

"Your meeting is scheduled for " + $json["formattedDate"]

Once you understand how to format date fields in n8n, your workflows become far more reliable, readable, and compatible across tools. Whether you're building a scheduler, automation dashboard, or simply logging tasks, proper date handling ensures everything runs right on time. You can further explore other n8n automation ideas or dive into passing data between nodes to level up your workflow-building skills.

★★★★★
50+ fixes, templates & explanations
Stuck with n8n errors?
Node-by-node breakdown.
Copy-paste templates.
Beginner friendly.
Get the n8n Beginners Guide
Built by AgentForEverything.com
Comments
Join the Discussion and Share Your Opinion
Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Newsletter
Get The Latest Agent Templates & Guides, Straight To Your Inbox.
Join the #1 AI Automation newsletter.