When formatting date from $now expression, the dd is one day ahead

Describe the problem/error/question

When using the $now expression, which currently returns [Object: “2023-11-24T23:41:14.595-05:00”], when I use the format node MM/DD/YYYY, I get 11/25/2023, instead of 11/24/2023.

This is occurring in template 1744 as well as in my own workflow I built separately.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

{
“meta”: {
“instanceId”: “5d81b031d071ea343947e29f1e3553f1aac61d04d0e5e9bd7aedadd24853ad2e”
},
“nodes”: [
{
“parameters”: {
“value”: “={{$now}}”,
“toFormat”: “=YYMMDD”,
“options”: {}
},
“name”: “Format - MMMM DD YY”,
“type”: “n8n-nodes-base.dateTime”,
“position”: [
1480,
40
],
“typeVersion”: 1,
“id”: “d9ff1157-e086-4fe9-bae8-2234c09799e8”
}
],
“connections”: {}
}

Share the output returned by the last node

I get 11/25/2023, instead of 11/24/2023.

Information on your n8n setup

  • n8n version: 1.16.0
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • **Operating system: Windows 10

Javascript in the Code Node has the same issue, as this returns 2023-11-25 instead of 2023-11-24. It’s almost like the timezone is in Germany where n8n.io is hosted??

// Create a new Date object
const today = new Date();

// Get the year, month, and day separately
const year = today.getFullYear();
// JavaScript months are zero-based (0 for January, 1 for February, etc.)
const month = today.getMonth() + 1; // Adding 1 to get the actual month
const day = today.getDate();

// Format the date as yyyy-mm-dd
const formattedDate = ${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')};

return {formattedDate} ; // Output: yyyy-mm-dd format of today’s date

Hi @ManOnFire1978
and welcome to the n8n community!

You can change the timezone of each workflow by clicking on the three dots top right and then Settings

Inside settings you will find the Timezone.
Let me know if that helps.

A side note: n8n uses the Luxon javascript library, so you can easily format your dates writing something like:
$now.toFormat('LL/dd/yyyy)
You can find the full list of Luxon’s tokens here: luxon - Immutable date wrapper

All the best

Hi @giulioandreini,

Thank you for the response. Through my investigation, I found that setting is correctly set to 'Default (GMT-05:00) Eastern Time.

I’ll redeploy template 1744 to a new workflow again tonight around 10:00 PM EST, confirm timezone settings, and see if it’s still a day ahead.

Do you suggest any other troubleshooting tips at this time?

Good tip on the simpler $now.toFormat! Thank you!

Thank you.

Hi @ManOnFire1978
that template is using old versions of our nodes,
I suggest trying to replace the nodes with the new ones, that could make your life easier (and also get you used to our most recent nodes).
Let me know if that works
Best

Will do thank you.