# \[scripted field\] convert String date to timestamp

**URL:** https://discuss.elastic.co/t/scripted-field-convert-string-date-to-timestamp/94885
**Category:** Kibana
**Created:** [July 28, 2017, 1:33am UTC](https://discuss.elastic.co/t/scripted-field-convert-string-date-to-timestamp/94885 "2017-07-28T01:33:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Hyojoung\_Shin](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Hyojoung\_Shin](https://discuss.elastic.co/u/Hyojoung_Shin)
#### Post date: [July 28, 2017, 1:33am UTC](https://discuss.elastic.co/t/scripted-field-convert-string-date-to-timestamp/94885/1 "2017-07-28T01:33:27Z")

</div>

Hi.

I am trying to calculate dates in scripted field.

If I want to calculated between elasticsearch field and date string, what should I do?

I think I need to convert string type date to timestamp.  
What is the way to do that?

if('2017-01-01'-doc['WK\_DT'].value \> 0){  
return '2017-01-01'-doc['WK\_DT'].value  
}else{  
return '-1'  
}

---

<div class="post-metadata">

### Author: ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)
#### Post date: [July 28, 2017, 3:32pm UTC](https://discuss.elastic.co/t/scripted-field-convert-string-date-to-timestamp/94885/2 "2017-07-28T15:32:37Z")

</div>

hi @Hyojoung_Shin,

to learn more about the date-maths supported by Painless, check out this [https://www.elastic.co/blog/using-painless-kibana-scripted-fields](https://www.elastic.co/blog/using-painless-kibana-scripted-fields).

more detailed documentation is here: [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-expression.html#\_date\_field\_api](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-expression.html#_date_field_api)

---

<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: [August 25, 2017, 3:33pm UTC](https://discuss.elastic.co/t/scripted-field-convert-string-date-to-timestamp/94885/3 "2017-08-25T15:33:18Z")

</div>

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