How Can I Convert a Numerical Date Format from CLICKUP to "yyyy-MM-ddThh:mm:ss" Format for Outlook in a Workflow?

This topic was automatically generated from Slack. You can find the original thread here.

I have created a workflow which foresees the following: when a task is added in the CLICKUP application, a new event is automatically loaded in the outlook calendar.
In the workflow I have to specify the start date and time and the end date and time of the event taken from CLICKUP
The date is provided to me by CLICKUP in numerical format, eg: 1693479600000 (see 2023-08-31_20-03-13 - TechSmith Screencast - TechSmith Screencast) while Outlook expects a “yyyy-MM-ddThh:mm:ss” format
If I simply click on the Start Date field, this data {{steps.trigger.event.task.start_date}} is loaded (see 2023-08-31_20-06-59 - TechSmith Screencast - TechSmith Screencast)
When I run the test I get this error
“Mistake”
Provide both start and end objects in “yyyy-MM-ddThh:mm:ss”
DETAILS
at Object.run (file:///tmp/pdg/dist/code/d7ff2b0eeb65f432bb5c42622cc041abef075bf0ed6a4c83b9ed84dbc294d0f2/code/actions/create-calendar-event/create-calendar-event.mjs:77:13)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

I think the date should be formatted but looking in the guide I couldn’t find any answers
Can anyone help me?
Thanks

how can we format a unix timestamp in this format: yyyy-MM-ddThh:mm:ss?

To format a Unix timestamp in the yyyy-MM-ddThh:mm:ss format, you can use the following code snippet in a Pipedream code step: const unixTimestamp = 1693479600000; const formattedDate = new Date(unixTimestamp).toISOString().slice(0, 19); console.log(formattedDate); This will convert the Unix timestamp to a JavaScript Date object, then format it as an ISO string and slice it to the required format.

What if we need to convert it to a specific timezone?

To convert a Unix timestamp to a specific timezone, you can use the Intl.DateTimeFormat function along with the timeZone option. Here’s an example code snippet for a Pipedream code step: const unixTimestamp = 1693479600000; const timeZone = "America/New_York"; // Replace with the desired timezone const formattedDate = new Intl.DateTimeFormat("en-US", { timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", }).format(new Date(unixTimestamp)); console.log(formattedDate); Replace timeZone with the desired timezone (e.g., “America/Los_Angeles”, “Europe/London”, etc.). This code will convert the Unix timestamp to the specified timezone and format it as yyyy-MM-ddThh:mm:ss.

: Does this help? :point_up_2:

Thank you I’m not very experienced
where should i put the code snipet?
I was expecting to have a way of formatting the date in the fields indicated by the arrows (see image)

it’s possible?

I don’t think it’s possible directly in the fields, because it’s not a simple transformation. :disappointed:

I would probably require a node.js code step.

Could you please put the code you provided in a pipedream node.js code step?

Certainly! Here’s the code snippet to convert a Unix timestamp to a specific timezone and format it as yyyy-MM-ddThh:mm:ss, placed within a Pipedream Node.js code step: import { defineComponent } from "pipedream"; export default defineComponent({ props: { unixTimestamp: { type: "integer", label: "Unix Timestamp", }, timeZone: { type: "string", label: "Timezone", default: "America/New_York", // Replace with the desired timezone }, }, async run({ steps, $ }) { const formattedDate = new Intl.DateTimeFormat("en-US", { timeZone: this.timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", }).format(new Date(this.unixTimestamp)); console.log(formattedDate); return formattedDate; }, }); This code step takes two input props: unixTimestamp and timeZone. You can customize the default timezone value or provide it when you run the step. The step will convert the Unix timestamp to the specified timezone and format it as yyyy-MM-ddThh:mm:ss.

You should be able to copy this into a node.js code step! :point_up_2:

: The code you provided returns the date in this format: MM/dd/yyyy, hh:mm:ss AM, but instead we want this format: yyyy-MM-ddThh:mm:ss

Apologies for the confusion. Here’s the updated code snippet to format the date in the yyyy-MM-ddThh:mm:ss format with a specific timezone: import { defineComponent } from "pipedream"; export default defineComponent({ props: { unixTimestamp: { type: "integer", label: "Unix Timestamp", }, timeZone: { type: "string", label: "Timezone", default: "America/New_York", // Replace with the desired timezone }, }, async run({ steps, $ }) { const date = new Date(this.unixTimestamp); const formatter = new Intl.DateTimeFormat("en-US", { timeZone: this.timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, }); const [ { value: month }, , { value: day }, , { value: year }, , { value: hour }, , { value: minute }, , { value: second }, ] = formatter.formatToParts(date); const formattedDate = `${year}-${month}-${day}T${hour}:${minute}:${second}`; console.log(formattedDate); return formattedDate; }, }); This code will convert the Unix timestamp to the specified timezone and format it as yyyy-MM-ddThh:mm:ss.

Ok, that works! :ok_hand:

Thanks Pi :pray:

: You can copy the latest code snippet in a Node step. :+1:

One of these:

image.png

thanks

I added Node by adding it as a step right after the Clickup step (is that correct?)