# Unable to format date and time correctly

**URL:** <https://discuss.elastic.co/t/unable-to-format-date-and-time-correctly/213217>\
**Category:** Elasticsearch\
**Created:** [December 27, 2019, 6:00pm UTC](https://discuss.elastic.co/t/unable-to-format-date-and-time-correctly/213217 "2019-12-27T18:00:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sidhusaab](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sidhusaab/32/60034_2.png) [@sidhusaab](https://discuss.elastic.co/u/sidhusaab)\
**Post date:** [December 27, 2019, 6:00pm UTC](https://discuss.elastic.co/t/unable-to-format-date-and-time-correctly/213217/1 "2019-12-27T18:00:13Z")

</div>

I have been reading on various forums here, on stackoverflow and java pages about date time formatting. I have syslog time stamp which is "Dec 10 01:23:44" format. I simply wanted to add year to the timestamp so I added `%{+YYYY}`. So now my JSON in elasticsearch looks like this:

I can see the `logdate` and `time` being parsed correctly but the `fields {}` is parsing it with full date stamp but in year 1970. If I combine the two fields together I still get year 1970.

```auto
    {
      "_index": "dns1_2019.12.27",
      "_source": {
        "dns_type": "zone_transfer",
        "type": "syslog",
        "@timestamp": "2019-12-27T17:29:23.590Z",
        "logdate": "2019-Dec-27",
        "time": "12:21:13",
      },
      "fields": {
        "@timestamp": [
          "2019-12-27T17:29:23.590Z"
        ],
        "logdate": [
          "1970-12-27T00:00:00.000Z"
        ],
        "time": [
          "1970-01-01T12:21:13.000Z"
        ]
      }
    }

```

---

<div class="post-metadata">

**Author:** ![sidhusaab](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sidhusaab/32/60034_2.png) [@sidhusaab](https://discuss.elastic.co/u/sidhusaab)\
**Post date:** [December 27, 2019, 9:08pm UTC](https://discuss.elastic.co/t/unable-to-format-date-and-time-correctly/213217/2 "2019-12-27T21:08:38Z")

</div>

So I combined the fields together manually creating `"dnstimestamp" => "2019-Dec-27 16:05:27"` which is now read properly.

This was my working grok before I cleaned up:

```auto
                  split => ["dns_timestamp", " "]
                  add_field => { "logdate" => "%{+YYYY}-%{[dns_timestamp][0]}-%{[dns_timestamp][1]}"
                                 "time" => "%{[dns_timestamp][2]}"
                                 "dnstimestamp" => "%{logdate} %{time}"
                               }
                  remove_field => ["message", "dns_timestamp"]
          }

```

---

<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:** [January 24, 2020, 9:08pm UTC](https://discuss.elastic.co/t/unable-to-format-date-and-time-correctly/213217/3 "2020-01-24T21:08:41Z")

</div>

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