# Convert @timestamp to string

**URL:** <https://discuss.elastic.co/t/convert-timestamp-to-string/33002>\
**Category:** Logstash\
**Created:** [October 26, 2015, 4:47pm UTC](https://discuss.elastic.co/t/convert-timestamp-to-string/33002 "2015-10-26T16:47:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paltryeffort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paltryeffort/32/28717_2.png) [@paltryeffort](https://discuss.elastic.co/u/paltryeffort)\
**Post date:** [October 26, 2015, 4:47pm UTC](https://discuss.elastic.co/t/convert-timestamp-to-string/33002/1 "2015-10-26T16:47:35Z")

</div>

I'd like to upgrade logstash 1.4 to 1.5. Before my logstash server processes the actual message I copy the @timestamp to a new field in order to know when the server received the message:  
mutate {  
add\_field =\> ["receive\_time", "%{@timestamp}"]  
}

In 1.5 @timestamp is now a date object which conflicts with the 1.4 (string) in elasticsearch. How do I copy and convert the @timestamp into a string in 1.5?

---

<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:** [October 26, 2015, 6:51pm UTC](https://discuss.elastic.co/t/convert-timestamp-to-string/33002/2 "2015-10-26T18:51:50Z")

</div>

I can't reproduce this with Logstash 1.5.4:

```
$ echo hello | /opt/logstash/bin/logstash -e 'input { stdin { } } filter { mutate { add_field => { "receive_time" => "%{@timestamp}" } } } output { stdout { codec => rubydebug } }'
Logstash startup completed
{
         "message" => "hello",
        "@version" => "1",
      "@timestamp" => "2015-10-26T18:51:17.096Z",
            "host" => "hallonet",
    "receive_time" => "2015-10-26T18:51:17.096Z"
}
Logstash shutdown completed
```

---

<div class="post-metadata">

**Author:** ![paltryeffort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paltryeffort/32/28717_2.png) [@paltryeffort](https://discuss.elastic.co/u/paltryeffort)\
**Post date:** [October 28, 2015, 3:04pm UTC](https://discuss.elastic.co/t/convert-timestamp-to-string/33002/3 "2015-10-28T15:04:29Z")

</div>

SOLVED:  
I was looking at the wrong place.  
The problem is that elasticsearch creates a date object instead of a string. To solve this I added this to my elasticsearch output template:

```
     "receive_time" : {
       "type" : "string"
     }

```

The only downside is that the format looks a bit different.

In logstash 1.4 it looks like "2015-10-28 15:08:09 +0100"  
In logstash 1.5 it looks like "2015-10-28T14:09:49.264Z"

I guess I have to live with that.

---

<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:** [July 6, 2017, 5:25am UTC](https://discuss.elastic.co/t/convert-timestamp-to-string/33002/4 "2017-07-06T05:25:02Z")

</div>


