How to convert JavaScript date format in a workflow step using props data?

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

Hey everyone,

I’m looking to do some javascript date conversion using the props data provided in a workflow step.

the step value is something like
timestamp:2023-06-02T17:51:02.864Z

and the output used for another step would convert it to “6/2/2023 5:51:02 PM”

I would normally put a javascript conversion within the {{steps.trigger.event.timestamp}} , but it looks like it would require a “new Date()“, which doesn’t seem to work within {{ }}

{{ new Date(steps.trigger.event.timestamp.toLocaleString().replace(“,”,“”) }}

Is there another way to do this with new ? I could write a nodejs step, but wanted to see if it can be done inline

Hi , in your custom expression, you can try to wrap (new Date()) into a bracket. For example:

(new Date()).toLocaleString()

Alternatively, Pipedream offers a prebuilt action that allow you to format the date, would you mind giving it a try?

Alternatively you can use Date.parse instead of new Date
See the documentation