# Scripted fields date parse

**URL:** <https://discuss.elastic.co/t/scripted-fields-date-parse/167241>\
**Category:** Kibana\
**Created:** [February 6, 2019, 8:31am UTC](https://discuss.elastic.co/t/scripted-fields-date-parse/167241 "2019-02-06T08:31:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedwe](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fedwe](https://discuss.elastic.co/u/fedwe)\
**Post date:** [February 6, 2019, 8:31am UTC](https://discuss.elastic.co/t/scripted-fields-date-parse/167241/1 "2019-02-06T08:31:46Z")

</div>

i extracted tweets from twitter and then i imported the json files into elasticsearch using kibana. I have this field called created\_at that has this format Wed Jan 30 18:12:02 +0000 2019 and i have not date field. i tried using scripted fields to parse it into a date by using :

new SimpleDateFormat('MMM D HH:mm:ss ZZ YYYY').parse(doc['created\_at'].value.substring(4)).getTime()

and i get a result of December 30th 2018, 18:12:02.000  
its giving December instead of January and 2018 instead of 2019

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [February 8, 2019, 5:56pm UTC](https://discuss.elastic.co/t/scripted-fields-date-parse/167241/2 "2019-02-08T17:56:36Z")

</div>

Hi there, the problem is your use of `YYYY`. This is the week-year, when you want the calendar year. Use `yyyy` and this will return the correct date. Reference: [https://stackoverflow.com/questions/14755742/java-date-year-calculation-is-off-by-year-for-two-days](https://stackoverflow.com/questions/14755742/java-date-year-calculation-is-off-by-year-for-two-days).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 8, 2019, 5:56pm UTC](https://discuss.elastic.co/t/scripted-fields-date-parse/167241/3 "2019-03-08T17:56:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
