String date to date property in automation/workflow with custom code

Really sorry for the confusion. It looks like HubSpot’s custom code function for workflows may not support the moment.js library. In that case, you can try using JavaScript’s built-in Date object to convert the string date to an ISO 8601 format.

try this:

exports.main = async (event, callback) => {
 const ca_date = event.inputFields['ca_date'];
 const date = new Date(ca_date);
 const isoDate = date.toISOString();
 console.log(isoDate);
 callback({
 outputFields: {
 date: isoDate
 }
 });
}

Here we’re creating a new Date object from the string date and then using the Date object’s toISOString() method to format it as an ISO 8601 string. You can then set the isoDate variable as the output field value, which should be in the correct format for HubSpot.