This topic was automatically generated from Slack. You can find the original thread here.
another one that should be pretty easy. One of the data outputs is a date time string like this “2023-05-31T10:55:41Z”
What is the best way to format that string into a usable date time value? Is there a method in nodeJS or is it better to do it in the Google Sheet that the data is pushed to?
if you want to format the date in each item in an array then it’s best to use the code. You can ask @U05A7KLNALC for it. For example
@U05A7KLNALC, I have an array with structure [ {"isodate": "2023-05-31T10:55:41Z"}, {"isodate": "2023-05-31T10:55:41Z"}], how can I format the isodate field to the date format MMMM DD YYYY HH:mm:ss using Nodejs
You can use the date-fns library to format the date in your array. First, you’ll need to import the parseISO and format functions from date-fns. Then, you can map through the array and format the isodate field. Here’s an example: import { parseISO, format } from 'date-fns'; const inputArray = [ { "isodate": "2023-05-31T10:55:41Z" }, { "isodate": "2023-05-31T10:55:41Z" } ]; const formattedArray = inputArray.map(item => { const parsedDate = parseISO(item.isodate); const formattedDate = format(parsedDate, "MMMM dd yyyy HH:mm:ss"); return { ...item, formattedDate }; }); console.log(formattedArray); This code will output an array with the formatted date: ```
on [ { “isodate”: “2023-05-31T10:55:41Z”, “formattedDate”: “May 31 2023 10:55:41” }, { “isodate”: “2023-05-31T10:55:41Z”, “formattedDate”: “May 31 2023 10:55:41” } ]
Here’s the code to format the date in a Pipedream Node.js action: ```
import { parseISO, format } from ‘date-fns’; export default defineComponent({ props: { isodate: { type: “string”, label: “ISO Date String”, description: “The ISO date string to be formatted”, }, dateFormat: { type: ‘string’, label: “Date Format”, description: “The desired date format, e.g. ‘MMMM dd yyyy HH:mm:ss’”, } }, async run({ steps, $ }) { const parsedDate = parseISO(this.isodate); const formattedDate = format(parsedDate, this.dateFormat); return formattedDate; }, });
, I have an array in params steps.list_participants with structure [ {"isodate": "2023-05-31T10:55:41Z"}, {"isodate": "2023-05-31T10:55:41Z"}], how can I format the isodate field to the date format MMMM DD YYYY HH:mm:ss using Pipedream Nodejs code action
You can format the isodate field in the array using the date-fns library. Here’s a Pipedream Node.js code action to achieve this: import { parseISO, format } from 'date-fns'; export default defineComponent({ props: { participants: { type: "string[]", label: "Participants", description: "Array of participants with isodate field", }, }, async run({ $ }) { const formattedParticipants = this.participants.map(participantJson => { const participant = JSON.parse(participantJson); const parsedDate = parseISO(participant.isodate); const formattedDate = format(parsedDate, "MMMM dd yyyy HH:mm:ss"); return { ...participant, formattedDate }; }); return formattedParticipants; }, }); Add this action to your workflow after the Zoom participation Object array step. It will take the array of participants as input and return an array with the formatted isodate field.