# How to convert String "date+time+tz" to timestamp

**URL:** <https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577>\
**Category:** Logstash\
**Created:** [January 15, 2018, 4:23pm UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577 "2018-01-15T16:23:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marouane/32/83858_2.png) [@marouane](https://discuss.elastic.co/u/marouane)\
**Post date:** [January 15, 2018, 4:23pm UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577/1 "2018-01-15T16:23:22Z")

</div>

Hello every one,  
I want to replace 3 fields that contains string(date) , string(time) and string(tz) by a new field with date type that contains (date+time+tz) converted.

```
{  
 "query":{  
 "bool":{  
     "must_not":{  
        "exists":{  
           "field":"new_date"
        }
     }
  }
},
"script":{  
  "inline":"ctx._source.new_date = ctx._source.date + ctx._source.time + ctx._source.tz",
  "lang":"groovy"
}
}

```

When i apply this , i got :

```
{
"error": {
"root_cause": [
  {
    "type": "script_exception",
    "reason": "error evaluating ctx._source.new_date = ctx._source.date + ctx._source.time + ctx._source.tz",
    "script_stack": [],
    "script": "",
    "lang": "groovy"
  }
],
"type": "script_exception",
"reason": "error evaluating ctx._source.new_date = ctx._source.date + ctx._source.time + ctx._source.tz",
"caused_by": {
  "type": "null_pointer_exception",
  "reason": "Cannot execute null+null"
},
"script_stack": [],
"script": "",
"lang": "groovy"
},
"status": 500
}

```

This is the string one , Now how can i convert This to timestamp

Thank you for your help

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 15, 2018, 5:27pm UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577/2 "2018-01-15T17:27:04Z")

</div>

So... you have an elasticsearch input in your Logstash configuration?

If yes, the general answer is to use a date filter on the `new_date` field. I can't be more specific than that without further details on what the `date`, `time`, and `tz` fields look like.

---

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marouane/32/83858_2.png) [@marouane](https://discuss.elastic.co/u/marouane)\
**Post date:** [January 16, 2018, 8:23am UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577/3 "2018-01-16T08:23:30Z")

</div>

Thank you for your reply,  
This is what i have :

```
GET myindex/_search
{
  "query": {
  "match_all": {}
  }
}

"hit": {
"total": 148563278,
"max_score": 1,
"hit": [
  {
    "_index": "myindex",
    "_type": "mytype",
    "_id": "1",
    "_score": 1,
    "_source": {
      "date": "2016-06-30",
      "tz": "UTC",
      "time": "10:21:16",

```

I want to :  
add 2 other fields:

- field1 = date\_time\_tz\_str ( string : concatenation of 3 fields )
- field2 = date\_time\_tz ( timestamp ) conversion of field ( date\_time\_tz\_str)

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 23, 2018, 11:32am UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577/4 "2018-01-23T11:32:34Z")

</div>

Use a mutate filter to concatenate the field values, then use a date filter to parse `field1` into `field2`.

---

<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:** [February 20, 2018, 11:33am UTC](https://discuss.elastic.co/t/how-to-convert-string-date-time-tz-to-timestamp/115577/5 "2018-02-20T11:33:11Z")

</div>

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