# Problems creating a scripted field for Date only from a datetime field

**URL:** <https://discuss.elastic.co/t/problems-creating-a-scripted-field-for-date-only-from-a-datetime-field/362969>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [July 11, 2024, 4:59pm UTC](https://discuss.elastic.co/t/problems-creating-a-scripted-field-for-date-only-from-a-datetime-field/362969 "2024-07-11T16:59:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![levitoh123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/levitoh123/32/106905_2.png) [@levitoh123](https://discuss.elastic.co/u/levitoh123)\
**Post date:** [July 11, 2024, 4:59pm UTC](https://discuss.elastic.co/t/problems-creating-a-scripted-field-for-date-only-from-a-datetime-field/362969/1 "2024-07-11T16:59:16Z")

</div>

This shouldn't be too complex but yet Painless is pretty painful. What I am trying to do is to get only the date from a datetime field in a format of "MMM D, YYYY" or simply "YYYY-MM-DD", so I can use it to make unique count of days for that field. I have attempted to create a scripted field and set the Type as Date and the script as this one:

```auto
ZonedDateTime zdt = ZonedDateTime.parse(
        doc['process_datetime_start'].value.toString()
    );
emit(zdt);

```

But this is producing this error:

```auto
Cannot cast from [java.time.ZonedDateTime] to [long]. Verify that you have correctly set the runtime field type.

```

 ![Screenshot 2024-07-11 at 12.56.12 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/4/94412a57105749c5d32778f6f1ea1d8d69fc30d7.png)

The documentation is quite confusing and I don't understand how this keeps trying to parse it to Long if I set the type as Date instead?

Thanks in advance,
