
Module 4 Lesson 4: Working with Dates
Master the fourth dimension. Learn how to format dates, add/subtract time, and handle timezone conversions using the world-class Luxon library inside n8n.
Module 4 Lesson 4: Working with Dates
Dates are the #1 source of headaches in programming.
- "What is 3 days from now?"
- "Convert UTC to Pacific Time."
- "Is this invoice overdue?"
n8n uses the Luxon library to make this manageable.
1. The $now Variable
n8n provides a helper for the current moment:
{ $now }-> Returns a full Luxon object.{ $now.toFormat('yyyy-MM-dd') }->"2025-12-21"
2. Adding & Subtracting Time
Need to set a reminder for 48 hours from now?
{ $now.plus({ hours: 48 }).toISO() }
Need to see if a date was more than a week ago?
{ $now.minus({ days: 7 }) > DateTime.fromISO($json.created_at) }
3. Formatting (Human Readable)
External APIs want ISO8601, but humans want "Monday, Dec 21st."
{ $now.setLocale('en-gb').toLocaleString(DateTime.DATE_HUGE) }
4. Timezone Conversions
{ DateTime.fromISO($json.start_time, { zone: 'utc' }).setZone('America/New_York').toString() }
- This is essential for international teams or scheduling webinars across continents.
Exercise: The Time Traveler
- Write an expression that returns the "Current Year."
- Calculate the date for "Last Tuesday."
- If an API returns
"2025-01-01T12:00:00Z", how do you extract just the "Hour" (12)? - Why is it always better to store dates in UTC in your database? (Review Module 2, Lesson 3).
- Research: What is the "Wait" node's "Wait until" feature? How would you use a dynamic expression there?
Summary
Date manipulation turns a "Static" automation into a "Time-aware" assistant. By mastering Luxon within n8n, you can build logic that understands deadlines, schedules, and the complex reality of global timezones.
Next Lesson: Final cleanup: Sorting, Filtering, and Limiting data.