# Formatting date and time in a preMp script

**URL:** <https://connective.celigo.com/t/formatting-date-and-time-in-a-premp-script/272>\
**Category:** Integrator.io\
**Tags:** script, hooks, import, netsuite\
**Created:** [December 8, 2023, 10:47pm UTC](https://connective.celigo.com/t/formatting-date-and-time-in-a-premp-script/272 "2023-12-08T22:47:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujitdesai](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sujitdesai](https://connective.celigo.com/u/sujitdesai)\
**Post date:** [December 8, 2023, 10:47pm UTC](https://connective.celigo.com/t/formatting-date-and-time-in-a-premp-script/272/1 "2023-12-08T22:47:27Z")

</div>

Hello, I need to process input data in a NetSuite Import Step before mapping.  
I need to extract the month, year values from the date field of the input data. The input date is in unix timestamp format. Does anyone knows what datetime formatting can be used inside the preMap script (or any kind of hook per say)?

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [December 9, 2023, 2:11am UTC](https://connective.celigo.com/t/formatting-date-and-time-in-a-premp-script/272/2 "2023-12-09T02:11:45Z")

</div>

@sujitdesai you can use the dayjs library. See doc example below. You most likely could use handlebar expressions as well just within the mapping instead of having to use a script.

Handlebar example:

[https://docs.celigo.com/hc/en-us/articles/360039326071-Handlebars-helper-reference#dateFormat](https://docs.celigo.com/hc/en-us/articles/360039326071-Handlebars-helper-reference#dateFormat)

```
{{dateFormat "MM" created "X" "America/Chicago"}}{{dateFormat "DD" created "X" "America/Chicago"}}{{dateFormat "YYYY" created "X" "America/Chicago"}}{{dateFormat "YYYY-MM-DD" created "X" "America/Chicago"}}
```

 ![5301043caa20740200000001-aba7f2d3db4d40138834f26f17339b06.png](https://us1.discourse-cdn.com/flex001/uploads/celigo/original/2X/4/4f32edb26a2c9286c4c0b9347f2c0d8924381f8e.png)

Script example:

[https://docs.celigo.com/hc/en-us/articles/10022222979739-Access-the-dayjs-JavaScript-library-in-scripts](https://docs.celigo.com/hc/en-us/articles/10022222979739-Access-the-dayjs-JavaScript-library-in-scripts)

```
import dayjs from 'dayjs';function test (options) { for (let d of options.data) { d.created_date = dayjs.unix(d.created).format('YYYY-MM-DD'); d.created_year = dayjs.unix(d.created).format('YYYY'); d.created_month = dayjs.unix(d.created).format('MM'); d.created_day = dayjs.unix(d.created).format('DD'); } return options;}
```

 ![5301043caa20740200000001-0abe190a9cd946079da2823e23f95ced.png](https://us1.discourse-cdn.com/flex001/uploads/celigo/original/2X/0/0a1f180ba29f363747fb3c1df60c5c53619d33a4.png)
