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.

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.

// 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
```text
A practical Code node for batch date transformation:

```javascript
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
    )
  }
}));
```text
Luxon handles timezone-aware parsing, locale formatting, and arithmetic -- covering virtually every date transformation scenario you will encounter.

**Related:** [Flatten Deeply Nested API Responses](../code-node-mastery/01-flatten-deeply-nested-api-responses.md) | [Use the HTTP Request Node as a Universal Connector](../integration-patterns/01-use-the-http-request-node-as-a-universal-connector.md)

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

191 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 a 20-minute call