Add hours to ISO time string

Hi, new to n8n and currently running the desktop app.
I have been setting up a workflow which pulls appointment data from a local CSV file and loads each to a task in clickup.
In the CSV I have access to the appointment date, time and duration in decimal hours e.g. “1.5”. Is it possible to create a function which will add the hours to the start date/time and create a due time in ISO format which can be read with the clickup node.

Input ISO start 2022-03-22T09:00:00.000 + add value from hours in CSV (example 2.5 hours) and return a time 2022-03-22T11:30:00.000

"appDate": "22/03/2022",
"appTime": "09:00",
"jobNo": 88241,
"desc1": "PRE NCT CHECK",
"desc2": "Check noise gearing down",
"hours": 1,
"mrkNo": 8073,
"title": "",
"FName": "removed",
"SName": "removed",
"add1": "removed",
"add4": "Waterford",
"email": "removed",
"mobile": 123456,
"reg": "161W0000",
"VIN": "NMTBN3JEX0R000000",
"make": "Toyota",
"model": "Corolla",
"nextSerDate": "27/07/2022",
"nextNCT": " ",
"regDate": 42615.999756944446,
"Start Date": "2022-03-22T09:00:00.000"

Hi @SteveMcc,

Welcome to the community, You can do this with the Date & Time node. The below code can be copy-pasted into n8n.
You will however sometimes need to use them both. one to add the hours, and one to set the format.
For me it give the datetime with a Z at the end for the UTC time. So I format it again to not get the UTC time but the normal time for me. Hope that makes sense.

Hope this answers the question.


Thanks @BramKnuever that works, the only issue I’m still having is after changing the item.myNewField to $json[“startTime”]; to pull the unique time for each item the datetime node is unable to parse the date correctly even though its still in the same format? Tried also change the from format value with no success.

Hi @SteveMcc

You do not need the function item node. This was just for me to get a value I could reference in the date&time node.
Have you tried just using the startTime field as the source for the date&time node? If this doesn’t work please show your workflow, so we can see what is going wrong.

1 Like

@BramKnuever Yes did also try using the startTime as the source and doesn’t seem to be able to parse it properly despite being the same?

Hi @SteveMcc

Sorry for the late reply.
The error shown gives you the issue quite clearly. The from format you set isn’t correct. Usually you do not use the from format unless it is not working. In this case it was not working because you had the wrong value selected. You use Starttime as a value, which is no value.
You needed to use: {{$json[“Start Date”]}}
Below is the JSON for the 2 Date & Time nodes to add the time and reformat the time. You can copy paste the JSON into n8n and connect it to your flow. I have changed the input to the correct field.