Course/Chapter 5/4. Working with Dates & Strings
    intermediate
    Chapter 5: Data Transformation & Manipulation

    4. Working with Dates & Strings

    Parse, format, and calculate dates. Manipulate strings.

    15m Lesson 4 of 5

    n8n uses Luxon for date manipulation — it's built into the expression editor. For strings, standard JavaScript methods are available plus n8n's helper functions.

    Code Examples

    Date Operations with Luxon
    javascript
    // In expressions:
    {{ DateTime.fromISO($json.date).toFormat("MMM dd, yyyy") }}
    {{ $now.minus({ days: 30 }).toISO() }}
    {{ DateTime.fromISO($json.start).diff(DateTime.fromISO($json.end), "hours").hours }}
    
    // In Code node:
    const { DateTime } = require("luxon");
    const created = DateTime.fromISO(item.json.created_at);
    const daysSince = Math.floor(DateTime.now().diff(created, "days").days);

    Pro Tips

    • 💡Always use Luxon instead of native JavaScript Date for timezone-safe date operations

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. Which library does n8n use for date manipulation?

    2. Why should you avoid native JavaScript Date in n8n?

    Pass the quiz above to unlock lesson completion