💬 RevOps Discussions

lana604
Member

Custom Code to change Date/Time stamp to Date

SOLVE

I have a workflow rule where I grab a date/time field with custom code and update that field to a date field (MM/DD/YYYY) as an output.

Example: 
Date/time: 2024-06-21T00:29:23.243Z
Date: 06/21/2024 

I receive a "Success" message when testing the custom code. However, when I copy the output date and input it into my "signup_date" field I receive a message saying "Unable to update property because property value isn't valid." I've played around with the format of the output date to YYYY/MM/DD and DD/MM/YYYY as well as with "-" instead of "/" ... but no luck! 😞

How can I fix this?


Custom CodeCustom CodeSuccess Message from CodeSuccess Message from CodeWorkflowWorkflowError MessageError Message

0 Upvotes
1 Accepted solution
Bortami
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Custom Code to change Date/Time stamp to Date

SOLVE

The date must best set to midnight in order to copy via native workflows. 

Here are my tests:

code usedcode used

output defined as datetimeoutput defined as datetimein milliseconds with time set to midnightin milliseconds with time set to midnightstring set to midnightstring set to midnight

Screenshot 2024-06-28 at 10.39.53 PM.png

 

Michelle Tabor michelle.tabor@lyntonweb.com

Solutions Engineer | Full Stack Developer | HubSpot Architect

Lynton HubSpot Elite Partner

View solution in original post

0 Upvotes
7 Replies 7
Bortami
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Custom Code to change Date/Time stamp to Date

SOLVE

The date must best set to midnight in order to copy via native workflows. 

Here are my tests:

code usedcode used

output defined as datetimeoutput defined as datetimein milliseconds with time set to midnightin milliseconds with time set to midnightstring set to midnightstring set to midnight

Screenshot 2024-06-28 at 10.39.53 PM.png

 

Michelle Tabor michelle.tabor@lyntonweb.com

Solutions Engineer | Full Stack Developer | HubSpot Architect

Lynton HubSpot Elite Partner

0 Upvotes
lana604
Member

Custom Code to change Date/Time stamp to Date

SOLVE

Thank you Bortami, this did the trick! 

To summarize to copy the date time fields to a date field, the custom code must change the date/time field to set to UNIX milliseconds at midnight. 

0 Upvotes
SteveHTM
Guide | Partner
Guide | Partner

Custom Code to change Date/Time stamp to Date

SOLVE

@lana604 - based on my own efforts on this topic, the only acceptable format for a date output from a custom code workflow is a timestamp value in milliseconds - not a formatted date string as you might expect. As in 1708905600000 rather than 2024-02-26.

 

Hope this helps!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
lana604
Member

Custom Code to change Date/Time stamp to Date

SOLVE

Hi Steve,

I updated the output code to time stamp value in milliseconds, unfortunately, when I copy the property value to my date field, I get the same error where "property value is not valid...." 

I'm thinking this might be a HubSpot limitation. I have developers looking into this but so far no luck .

0 Upvotes
RThomas11
Member

Custom Code to change Date/Time stamp to Date

SOLVE

What is the field type for that signup_date custom field?

0 Upvotes
lana604
Member

Custom Code to change Date/Time stamp to Date

SOLVE

It's a Date Picker field. My date format is the United States, so MM/DD/YYYY.

lana604_0-1719251035563.png

I do not have any validation rules associated to the field.

lana604_1-1719251141158.png

 

 

0 Upvotes
RThomas11
Member

Custom Code to change Date/Time stamp to Date

SOLVE

That and check for property validation rules 

0 Upvotes