Tips > Data, APIs & Webhooks

Transform Date Formats Between APIs Using Luxon

Different APIs use wildly different date formats -- ISO 8601, Unix timestamps, US format, European format.

n8n bundles the Luxon library globally as DateTime, so you can parse and reformat dates between any API formats without external dependencies. Convert Unix timestamps, ISO 8601 strings, and non-standard layouts, shift time zones, and do date arithmetic directly in expressions, or process a whole batch inside a Code node that requires luxon.

What is Luxon in n8n?

Different APIs use wildly different date formats -- ISO 8601, Unix timestamps, US format, European format. n8n includes the Luxon library globally as DateTime, giving you full control over parsing and formatting without external dependencies.

Real-world example: Your source API (Stripe) returns dates as Unix timestamps. Your destination (a project management tool) expects dd/MM/yyyy format. Meanwhile, your logging database wants ISO 8601.

How do you convert date formats in expressions?

// Unix timestamp to human-readable
{{ DateTime.fromSeconds($json.created).toFormat('dd/MM/yyyy') }}
// Input: 1710504000 → Output: "15/03/2024"

// ISO string to US format
{{ DateTime.fromISO($json.created_at).toFormat('MM/dd/yyyy hh:mm a') }}
// Input: "2024-03-15T14:30:00Z" → Output: "03/15/2024 02:30 PM"

// Parse a non-standard format
{{ DateTime.fromFormat($json.event_date, 'yyyy-dd-MM').toISO() }}
// Input: "2024-15-03" → Output: "2024-03-15T00:00:00.000+00:00"

// Timezone conversion
{{ DateTime.fromISO($json.utc_time).setZone('America/New_York').toFormat('ff') }}
// Input: "2024-03-15T14:30:00Z" → Output: "Mar 15, 2024, 10:30 AM"

// Relative time calculation
{{ DateTime.fromISO($json.due_date).diff(DateTime.now(), 'days').days.toFixed(0) }}
// Returns number of days until due date

// Add/subtract time
{{ DateTime.now().minus({ days: 7 }).toISO() }}
// Returns ISO timestamp for exactly 7 days ago

How do you transform dates for a whole batch?

A practical Code node for batch date transformation:

const items = $input.all();
const { DateTime } = require('luxon');

return items.map(item => ({
  json: {
    ...item.json,
    created_display: DateTime.fromSeconds(item.json.created)
      .toFormat('dd MMM yyyy'),
    created_iso: DateTime.fromSeconds(item.json.created).toISO(),
    days_ago: Math.floor(
      DateTime.now().diff(DateTime.fromSeconds(item.json.created), 'days').days
    )
  }
}));

Luxon handles timezone-aware parsing, locale formatting, and arithmetic -- covering virtually every date transformation scenario you will encounter.

Related: Flatten Deeply Nested API Responses · Use the HTTP Request Node as a Universal Connector

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

190 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book an introductory call