# Changing Close Time to Decimal Hours

**URL:** <https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916>\
**Category:** CMS Development\
**Tags:** local-development, javascript, enterprise\
**Created:** [April 7, 2023, 2:00pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916 "2023-04-07T14:00:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TSweet2](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TSweet2](https://community.hubspot.com/u/TSweet2)\
**Post date:** [April 7, 2023, 2:00pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916/1 "2023-04-07T14:00:41Z")

</div>

Hello,

I am trying to using a workflow with a custom code snippet in order to change the ticket close time property over into decimal time. The process that I have so far is using a “Format data” action that changes the time to close of a ticket into a unix time (String), and then using a custom code snippet that will then turn that unix time into decimal hours (Number). I think the errors that I am experiencing might be around how I input the variable at the start of the code and the fact that I am attempting to turn a string into a number value. Here are some screenshots and an export of the code, if there is anything else that you think would be helpful to know then feel free to ask. Thanks

 ![TSweet2_0-1680875670102.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/3/0323651615ecb4f5564de87ad4c142d29c505e06.png)

 ![TSweet2_1-1680875698301.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/b/7/b778caad37c315ef74a7a02e8782376579bc85af.png)

 ![TSweet2_2-1680875716417.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/7/e7180d2e1a0194a2abd1a0160fc50a0064796a24.png)

exports.main = async (event, callback) =\> {  
const unixTime = event.inputfields[‘time\_to\_close\_unix’];  
const date = new Date(unixTime \* 1000);  
const secondsSinceStartOfDay = (date.getHours() \* 3600) + (date.getMinutes() \* 60) + date.getSeconds();  
const closeDecimalHours = secondsSinceStartOfDay / 3600;  
callback ({ outputFields: { number: closeDecimalHours } } ) ; }

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [April 10, 2023, 5:34pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916/2 "2023-04-10T17:34:39Z")

</div>

Hey, @TSweet2 👋 Can you share the error(s) you are receiving? This may help the community to better understand your issue.

If the community trues to reproduce this, outside the code and the custom ticket property, is there anything else that’s vital to include? It doesn’t look like it. It seems pretty straightforward.

Thanks! — Jaycee

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [April 10, 2023, 7:55pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916/3 "2023-04-10T19:55:15Z")

</div>

Hi, @TSweet2. Thanks for adding the error body. One additional question – what are the type and fieldType for your custom property? You can verify it with this call:

`https://api.hubapi.com/crm/v3/properties/tickets/time_to_close_unix?archived=false`

Thanks! — Jaycee

---

<div class="post-metadata">

**Author:** ![TSweet2](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TSweet2](https://community.hubspot.com/u/TSweet2)\
**Post date:** [April 10, 2023, 9:36pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916/4 "2023-04-10T21:36:38Z")

</div>

[@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) Where would I go about running this code snippet? I apologize if this is an easy question, I am still new operations in Hubspot

---

<div class="post-metadata">

**Author:** ![TSweet2](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TSweet2](https://community.hubspot.com/u/TSweet2)\
**Post date:** [April 10, 2023, 6:32pm UTC](https://community.hubspot.com/t/changing-close-time-to-decimal-hours/78916/5 "2023-04-10T18:32:58Z")

</div>

Hey [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) , I think the errors are relating to the property fields. Let me know if you need any other information.

The event error that I got was:  
The custom code threw an error. This could be due to a syntax error in the code, an error being returned by an API, or some other issue with the code.

The log error was:

```auto
ERROR	Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot read properties of undefined (reading 'time_to_close_unix')","reason":{"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'time_to_close_unix')","stack":["TypeError: Cannot read properties of undefined (reading 'time_to_close_unix')"," at Object.exports.main (/var/task/file.js:3:26)"," at Runtime.exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:6:21)"," at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1085:29)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'time_to_close_unix')"," at process.<anonymous> (file:///var/runtime/index.mjs:1188:17)"," at process.emit (node:events:513:28)"," at emit (node:internal/process/promises:140:20)"," at processPromiseRejections (node:internal/process/promises:274:27)"," at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
Unknown application error occurred
Runtime.Unknown

Memory: 58/128 MB
Runtime: 75.67 ms

```
