# Merge date and time field

**URL:** <https://discuss.elastic.co/t/merge-date-and-time-field/242862>\
**Category:** Logstash\
**Created:** [July 28, 2020, 8:28am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862 "2020-07-28T08:28:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bigranawab](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@Bigranawab](https://discuss.elastic.co/u/Bigranawab)\
**Post date:** [July 28, 2020, 8:28am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/1 "2020-07-28T08:28:54Z")

</div>

So, I have been trying to parse fortigate logs using logstash, I came across date and time fields, in fortigate there are two different fields, I tried to parse those fileds  
using

```auto
mutate {add_field => { "@timestamp" => "%{date} %{time}" }}
date {
    match => ["@timestamp", "MMM dd yyyy HH:mm:ss", "MMM d yyyy HH:mm:ss", "ISO8601"]
    timezone => "Asia/Karachi"
    #target => "@timestamp"
    }

```

and I got below mentioned ans  
date=2020-07-28 time=01:24:44  
"@timestamp" =\> 2020-07-28T08:31:40.739Z  
where date is correct by time is 8 rather than 01,  
can someone help here

---

<div class="post-metadata">

**Author:** ![Bigranawab](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@Bigranawab](https://discuss.elastic.co/u/Bigranawab)\
**Post date:** [July 28, 2020, 8:29am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/2 "2020-07-28T08:29:37Z")

</div>

In my original config target field is not commented

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 28, 2020, 8:32am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/3 "2020-07-28T08:32:45Z")

</div>

> [@Bigranawab](#):
>
> date=2020-07-28 time=01:24:44

Is that the value of `%{date}` and `%{time}`?

---

<div class="post-metadata">

**Author:** ![Bigranawab](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@Bigranawab](https://discuss.elastic.co/u/Bigranawab)\
**Post date:** [July 28, 2020, 8:41am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/4 "2020-07-28T08:41:08Z")

</div>

yes it is

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 28, 2020, 10:07am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/5 "2020-07-28T10:07:34Z")

</div>

I see two problems:

1. That should have given you a `_mutate_error` when you tried to overwrite `@timestamp` with an array (by adding a second value to the existing one) as it has to be a timestamp.
2. Your date patterns don't match your input.

You can do it like this:

```auto
mutate {
    add_field => { "ts" => "%{date}T%{time}" }
}
date {
  match => ["ts", "ISO8601"]
  timezone => "Asia/Karachi"
  remove_field => "ts"
}

```

---

<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, 2020, 10:07am UTC](https://discuss.elastic.co/t/merge-date-and-time-field/242862/6 "2020-08-25T10:07:38Z")

</div>

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