Returning Date Information

I can get the current phonetic month when doing a simple new Date() but for some reason when I try to reference data sent in a webhook, it doesn’t return any data… any thoughts on what’s going on here? The data being sent by the webhook is an ISO date as a string.

const results = []
const date = $node["Webhook"].json.query["date"];
const d = new Date(date);

const month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
const n = month[d.getMonth()];

results.push({json:{n}})

return results

Hey @pford, just tried out the code that you shared and it works correctly for me. Could you perhaps share some more information about how you are sending input to the webhook and the value that you are passing?

Here’s my workflow in case it is helpful for you to debug :slight_smile:

And here’s the GET request that I made using my browser: http://localhost:5678/webhook-test/04b7a852-cc78-4d85-b4bc-b83140634306?date=2011-09-05T14:48:00.000Z (might need edits depending on your workflow/how you are running n8n).

Thanks for testing this for me! I also was able to do it with this version of the ISO timestamp but for some reason the service I’m using is sending the ISO as this: "date": "2021-12-19T23:24:30 00:00" instead of the correct format and I think that may be the issue. I know I can use the Date & Time node to convert this, but I’m not sure what the format specifiers should be to correct the final format that is put into the Function node.

1 Like

Nevermind I got it. The proper date format specifier to get it to work with new Date() is YYYY-MM-DDTHH:mm:ss.SSSZ

Thank you for helping me trouble shoot that @tanay!

2 Likes

Yay, glad to hear that it worked out. Have fun! :slight_smile: