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

**URL:** <https://community.hubspot.com/t/string-date-to-date-property-in-automation-workflow-with-custom-code/79501>\
**Category:** APIs & Integrations\
**Tags:** python, workflows\
**Created:** [April 18, 2023, 1:04am UTC](https://community.hubspot.com/t/string-date-to-date-property-in-automation-workflow-with-custom-code/79501 "2023-04-18T01:04:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Expertopinionsa](https://avatars.discourse-cdn.com/v4/letter/e/a183cd/32.png) [@Expertopinionsa](https://community.hubspot.com/u/Expertopinionsa)\
**Post date:** [April 18, 2023, 8:44am UTC](https://community.hubspot.com/t/string-date-to-date-property-in-automation-workflow-with-custom-code/79501/2 "2023-04-18T08:44:50Z")

</div>

Hi, it looks like the code you provided is converting the string date to a Unix timestamp (in seconds), which may not be compatible with HubSpot’s date format. HubSpot expects a date value in ISO 8601 format, which is “yyyy-mm-ddThh:mm:ssZ”.

You can modify your code to convert the string date to the ISO 8601 format before setting it as the output field value.

Here’s an example implementation using the moment.js library:

```lia-code-sample
const moment = require('moment');

exports.main = async (event, callback) => {
 const ca_date = event.inputFields['ca_date'];
 const date = moment(ca_date, 'MM/DD/YY').format('YYYY-MM-DDTHH:mm:ssZ');
 console.log(date);
 callback({
 outputFields: {
 date: date
 }
 });
}

```

In this implementation, we’re using moment.js to parse the string date with the ‘MM/DD/YY’ format and format it as an ISO 8601 string using ‘YYYY-MM-DDTHH:mm:ssZ’. You can then set the date variable as the output field value, which should be in the correct format for HubSpot. We always work in this manner at Triotech Systems. I hope this helps!

---

_[View the full topic](https://community.hubspot.com/t/string-date-to-date-property-in-automation-workflow-with-custom-code/79501)._
