Multiple date formats on date property in personalization

@TGeorge1 & @mpherr

I totally agree that this should be standard funtionality in any CRM product and I had a session with the HubSpot product managers about 9 month ago and told them this. It doesn’t look like it is going to be fixed though.

So I have resolved this using custom JS code in a workflow and calling the HubSpot API. This allows me to extract a date from a field and then format it into a date format that I want and store it in a custom field. Im currently storing it as a long format (5th March 2023) but that can be changed to any other format.

I run this everyday against all of my deals to get a format against the deal that I can us to email the expiry date in a UK format. It works really well
I have my deal enrolment trigger on my workflow and the rest of my workflow looks like this

My custom code action has the following code:

const hubspot = require(‘@hubspot/api-client’);
exports.main = (event, callback) => {

// Set up the HubSpot API client
const hubspotClient = new hubspot.Client({
accessToken: process.env.sec_key
});

hubspotClient.crm.deals.basicApi.getById(event.object.objectId, [“license_requested”])
.then(results => {
let selectedDate = results.properties.license_requested;
//Test point to see what the date is
//console.log(“end date is " + selectedDate);
let splitDate = selectedDate.split(”-");
let dayNow = splitDate[2];
let monthNow = splitDate[1];
let yearNow = splitDate[0];
let daySuffix = “”;

// console.log("Month now is " + monthNow);
switch (dayNow) {
case “1”:
case “21”:
case “31”:
daySuffix = “st”;
break;
case “2”:
case “22”:
daySuffix = “nd”;
break;
case “3”:
case “23”:
daySuffix = “rd”;
break;
default:
daySuffix = “th”;
break;
}
let monthName = “”;
switch (monthNow) {
case “01”:
monthName = “January”;
break;
case “02”:
monthName = “February”;
break;
case “03”:
monthName = “March”;
break;
case “04”:
monthName = “April”;
break;
case “05”:
monthName = “May”;
break;
case “06”:
monthName = “June”;
break;
case “07”:
monthName = “July”;
break;
case “08”:
monthName = “August”;
break;
case “09”:
monthName = “September”;
break;
case “10”:
monthName = “October”;
break;
case “11”:
monthName = “November”;
break;
case “12”:
monthName = “December”;
break;
default:
monthName = “Error”;
break;
}
let cs_expiry_date = dayNow + daySuffix + " " + monthName + " " + yearNow;

callback({
outputFields: {
cs_license_expiry_date_long: cs_expiry_date
}
});
})
.catch(err => {
console.error(err);
});
}

I am happy to discuss and answer what questions I can. Hapy to be contacted directly as well.