# Fetch and format date in Workflow

**URL:** <https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888>\
**Category:** Data Hub\
**Tags:** format-data-actions\
**Created:** [June 7, 2024, 8:44am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888 "2024-06-07T08:44:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![svamann](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svamann/32/77496_2.png) [@svamann](https://community.hubspot.com/u/svamann)\
**Post date:** [June 7, 2024, 8:44am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/1 "2024-06-07T08:44:22Z")

</div>

I have a workflow that fetches a Date property from a custom object in custom code and returns this.

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/6/f62b2eba3c6f5ffa6d6b327a83b6b07d3164237d.png)

This steps works like a charm, returning the expected value when I test it.

 ![Screenshot 2024-06-07 at 10.37.16.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/b/9bd62d03bc22be9e365df1f65d84b387d236096b.png)

Now at a later point in the same workflow, I try to format the date for display purposes, depending on conversation language, so there’s multiple branches doing a different formatting each. Since event\_start is a Date (tried Datetime as well), I assumed I can use a Format data step like this:

 ![Screenshot 2024-06-07 at 10.40.27.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/4/422b6f78dc543f8ef245dfb4ad31787a174277e7.png)

But this step fails when the workflow runs. Its kinda hard to debug, because the log just says “Action failed” without any more details. I assume that somehow the format of event\_start does not match the expectations of the Format data step.

Before I now replace the Format data step by another custom code, I would be curious whether I’m doing something wrong or whether this is indeed not possible this way 🤔

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [June 7, 2024, 3:33pm UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/2 "2024-06-07T15:33:34Z")

</div>

Hey @svamann, Happy Friday!

It looks like you’re encountering an issue with formatting a date in your workflow. Ensure that the date format returned by your custom code matches the expected format for the Format data step. The Format data step might require a specific date format (e.g., ISO 8601).

To our top experts @danmoyle and **@HFisher7** do you have any recommendations for @svamann matter?

Thank you,

Pam

---

<div class="post-metadata">

**Author:** ![danmoyle](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danmoyle/32/91166_2.png) [@danmoyle](https://community.hubspot.com/u/danmoyle)\
**Post date:** [June 11, 2024, 12:49pm UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/3 "2024-06-11T12:49:45Z")

</div>

Honestly I’d tag in @Jnix284 on this one. I think she’s done some custom coding in workflows - more than me, anyway!

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [June 18, 2024, 7:35pm UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/4 "2024-06-18T19:35:45Z")

</div>

Thanks for the tag @danmoyle and I apologize for the delayed response @svamann - were you able to solve the issue with your CCA?

---

<div class="post-metadata">

**Author:** ![svamann](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svamann/32/77496_2.png) [@svamann](https://community.hubspot.com/u/svamann)\
**Post date:** [June 18, 2024, 11:34pm UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/5 "2024-06-18T23:34:01Z")

</div>

I worked around it with custom code. Works, but I would sure like to understand why the formatting action fails… would be much more convenient to just use the native formatting action!

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [June 19, 2024, 12:58am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/6 "2024-06-19T00:58:09Z")

</div>

I’m glad you found a solution @svamann, without rebuilding the workflow and CCA, it’d be hard to say why it failed based on the info provided.

---

<div class="post-metadata">

**Author:** ![svamann](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svamann/32/77496_2.png) [@svamann](https://community.hubspot.com/u/svamann)\
**Post date:** [June 19, 2024, 6:46am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/7 "2024-06-19T06:46:12Z")

</div>

So what information would you need to answer this?

I’m fetching the date property from the API in my custom code.

and return the value as is

 ![Screenshot 2024-06-19 at 08.42.12.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/9/e9ac4a804ef70524e209118f406cef11ac58b72d.png)

The return type is declared as Date (using DateTime, makes no difference). And displays as “2024-06-12” when I test the step (see the screenshot in my original post above).

This output I seen directly feed into the format-date action.

From the above a gather that this might be an issue of the data format. I assumed that any “Date” would fit into a format date step and I can’t find any explicit requirement on the date format of such a step. If there is, I’d appreciate a pointer!

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [June 19, 2024, 11:38am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/8 "2024-06-19T11:38:19Z")

</div>

@svamann you said that it doesn’t matter if you use Date or DateTime, but there is a differentiation in the backend - how is start\_date defined? Is it a date picker (date) or DateTime?

Here’s the [dev doc for Date vs DateTime](https://developers.hubspot.com/docs/api/faq#:~:text=For%20values%20that%20represent%20a,%2DDDThh%3Amm%3Ass.) - I think this is the source of the error

---

<div class="post-metadata">

**Author:** ![svamann](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svamann/32/77496_2.png) [@svamann](https://community.hubspot.com/u/svamann)\
**Post date:** [June 19, 2024, 11:53am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/9 "2024-06-19T11:53:34Z")

</div>

@Jnix284 it’s a date picker. Choosing either Date or DateTime for the custom code output does not make an observable difference in the output I see when testing the custom code action (it’s “yyyy-mm-dd” in both cases) and in the error I see from the format date action. There may, of course, be a difference in what happens under the hood.

Thanks for the link, it explains the output format of the API, which matches what I see when testing my custom code action. Is there also documentation on the expected input format of the format date action?

I always thought it’s just not possible to create DateTime custom properties at all, now I learned it’s possible via the API! Thanks for this insight 🙂

---

<div class="post-metadata">

**Author:** ![svamann](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svamann/32/77496_2.png) [@svamann](https://community.hubspot.com/u/svamann)\
**Post date:** [September 26, 2024, 9:19am UTC](https://community.hubspot.com/t/fetch-and-format-date-in-workflow/108888/10 "2024-09-26T09:19:38Z")

</div>

I just figured this out at last. The custom code (Python in my case) needs to return the date as a timestamp in milliseconds and ensure that it is an integer. As in

`int(mydatetime.timestamp() * 1000)`

Then returning this from the custom code as a “Date” and using it in a Format Date action or writing it to a DatePicker property does work.

See also [this community thread](https://community.hubspot.com/t5/128172-RevOps-Discussions/Custom-Code-to-change-Date-Time-stamp-to-Date/m-p/1046272/highlight/true#M2699).
