Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created April 1, 2025 00:04
Show Gist options
  • Select an option

  • Save danielrosehill/b951233f6070e37cce0db122bfd33e4f to your computer and use it in GitHub Desktop.

Select an option

Save danielrosehill/b951233f6070e37cce0db122bfd33e4f to your computer and use it in GitHub Desktop.
Nicer timestamps in N8N

Luxon toFormat() Examples for n8n

Here are several examples of how to format dates and times using the Luxon library's toFormat() function within n8n's Expression node. These examples assume you want to generate a timestamped folder name.

Note: These examples use DateTime.now() to get the current date and time. Remember that this uses the n8n server's timezone by default. You can specify a timezone using .setZone('Your/Timezone').

Examples:

  1. ddmmyy_hhmm (Date and Time - as requested)

    {{ DateTime.now().toFormat('ddMMyy_HHmm') }}
    // Example Output: 010425_1435 (April 1, 2025, 2:35 PM)
  2. ddmmyy (Date Only)

    {{ DateTime.now().toFormat('ddMMyy') }}
    // Example Output: 010425 (April 1, 2025)
  3. yyyymmdd (Date Only - ISO style)

    {{ DateTime.now().toFormat('yyyyMMdd') }}
    // Example Output: 20250401 (April 1, 2025)
  4. mmddyyyy (Date Only - US style)

    {{ DateTime.now().toFormat('MMddyyyy') }}
    // Example Output: 04012025 (April 1, 2025)
  5. yyyy-MM-dd (Date Only - ISO with Hyphens)

    {{ DateTime.now().toFormat('yyyy-MM-dd') }}
    // Example Output: 2025-04-01 (April 1, 2025)
  6. hhmmss (Time Only)

    {{ DateTime.now().toFormat('HHmmss') }}
    // Example Output: 143542 (2:35:42 PM)
  7. HH:mm:ss (Time with colons)

    {{ DateTime.now().toFormat('HH:mm:ss') }}
    //Example Output: 14:35:42
  8. yyyyMMdd_HHmmss (Date and Time - All numbers)

    {{ DateTime.now().toFormat('yyyyMMdd_HHmmss') }}
    // Example Output: 20250401_143542 (April 1, 2025, 2:35:42 PM)
  9. MMMM dd, yyyy (Long Date Format)

    {{ DateTime.now().toFormat('MMMM dd, yyyy') }}
    // Example Output: April 01, 2025
  10. EEE, MMM d, ''yy (Short Date with Day)

{{ DateTime.now().toFormat("EEE, MMM d, ''yy") }}
// Example Output: Tue, Apr 1, '25
 ```

11. **yyMMddHHmmssSSS (Including milliseconds)**

 ```javascript
 {{ DateTime.now().toFormat('yyMMddHHmmssSSS') }}
 // Example Output: 250401143542123 (April 1, 2025, 2:35:42 PM and 123 milliseconds)
 ```

12. **yyMMdd_HH-mm-ss (Date and Time with mixed separators)**

```javascript
{{ DateTime.now().toFormat('yyMMdd_HH-mm-ss') }}
// Example output: 250401_13-44-22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment