Convert date format

Hi! I’m trying to figure out how to convert a date I get in a message as 2021-05-17 to either 05-17-2021 or Monday, May 17, 2021. I only need this to display this date in a more friendly format in an html email.

Any ideas? Thanks!

Would some combination of toISOString and/or getDay work for you?

So… yourDate.toISOString()

If you need the day of the week, that second function should let you convert. Not sure if anyone has other ideas for quickly getting to specific string formats. I wonder if it’s worth providing something like date-fns - npm in one of the adaptors. (Which adaptor are you using, btw?)

Thanks, Taylor! This is way over my head. I will reach out to our support team for help on this. Cheers!

Ah sorry about that. If your job looks like this:

operation(thing, fields(
  field('date for humans', dataValue('path'))
));

you’d want to instead do something like:

operation(thing, fields(
  field('date for humans', new Date(dataValue('path')).toString())
));

or, to be more explicit and give you a bit more flexibility you could write:

operation(thing, fields(
  field('date for humans', state => {
    const date = new Date(state.data.path); // this converts your initial string into a Javascript date.
    return date.toString(); // this turns your Javascript date into a human-friendly string
  })
));