# How to special date time format to timestamp format

**URL:** https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444
**Category:** Logstash
**Created:** [December 5, 2022, 7:47am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444 "2022-12-05T07:47:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![akif\_bal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akif_bal/32/114211_2.png) [@akif\_bal](https://discuss.elastic.co/u/akif_bal)
#### Post date: [December 5, 2022, 7:47am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/1 "2022-12-05T07:47:40Z")

</div>

I have a log type that I cannot manipulate. How can I convert the Time format in the log to timestamp format?  
Example log: "0001 021222 095725 00240541029896158 11 00 00 0000000000 000 0"  
Date and time that comes with the log: 021222 095725  
thanks in advance for your help

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 5, 2022, 8:11am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/2 "2022-12-05T08:11:54Z")

</div>

Are you trying to do it via logstash?

If yes, you can use GROK Pattens to match it and using mutate filter you can convert any field to date format.

---

<div class="post-metadata">

### Author: ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)
#### Post date: [December 5, 2022, 9:36am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/3 "2022-12-05T09:36:50Z")

</div>

Not sure what a date format do you have.

```auto
filter {

	grok {
		match => { "message" => "%{NUMBER:somenum}%{SPACE}%{NUMBER:date1}%{SPACE}%{NUMBER:date2}%{SPACE}" }
	}

	mutate { add_field => { "[date]" => "%{[date1]}%{[date2]}"} }

	date { 
		match => ["date", "MM/dd/yyyy HH:mm:ss"] # put your format
	}
}

```

---

<div class="post-metadata">

### Author: ![akif\_bal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akif_bal/32/114211_2.png) [@akif\_bal](https://discuss.elastic.co/u/akif_bal)
#### Post date: [December 5, 2022, 11:00am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/4 "2022-12-05T11:00:28Z")

</div>

![elkstack](https://us1.discourse-cdn.com/elastic/original/3X/f/c/fc5bde43d92b195851e5bc57e013ba604c96a200.png)  
I want to replace the log time recorded by the system in timestamp

---

<div class="post-metadata">

### Author: ![akif\_bal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akif_bal/32/114211_2.png) [@akif\_bal](https://discuss.elastic.co/u/akif_bal)
#### Post date: [December 5, 2022, 11:07am UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/5 "2022-12-05T11:07:53Z")

</div>

Thank you, I will try

---

<div class="post-metadata">

### Author: ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)
#### Post date: [December 5, 2022, 12:03pm UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/6 "2022-12-05T12:03:30Z")

</div>

Code:

```auto
filter {

	grok {
		match => { "message" => "%{NUMBER}%{SPACE}%{NUMBER:[@metadata][date]}%{SPACE}%{NUMBER:[@metadata][time]}%{SPACE}" }
	}

	mutate { add_field => { "[@metadata][datetime]" => "%{[@metadata][date]}%{[@metadata][time]}"} }

	date {
		match => ["[@metadata][datetime]", "ddMMyyHHmmss" ] # put your format
		timezone => "Asia/Dubai" # Set your own or leave it as it is
		target=> "@timestamp" # default destination field
	}
}

```

Result:

```auto
    "@timestamp" => 2022-09-16T13:17:01.000Z,
     "@metadata" => {
            "date" => "160922",
            "time" => "171701",
        "datetime" => "160922171701"
    }

```

---

<div class="post-metadata">

### Author: ![akif\_bal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akif_bal/32/114211_2.png) [@akif\_bal](https://discuss.elastic.co/u/akif_bal)
#### Post date: [December 5, 2022, 1:09pm UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/7 "2022-12-05T13:09:56Z")

</div>

I want to use the datetime in the log record because the datetime in the log and the time the logs are read do not match.

our grok filter

````auto
 grok {
      match => {"message" => ["%{WORD:TERMINAL_NO} %{MONTHDAY:day}%{MONTHNUM:month}%{YEAR:year} %{HOUR:hour}%{MINUTE:minute}%{SECOND:second} %{WORD:CARD_NUMBER} %{WORD:Event1} %{WORD:Event2} %{WORD:Event3} %{WORD:Event4} %{WORD:Event5} %{WORD:Event6}"] }

      remove_field => "message"
    }
    mutate {
      add_field => { "date" => "%{day}%{month}%{year} %{hour}%{minute}%{second}" }
    }

    date {
      match => ["date", "MM/dd/yyy HH:mm:ss"]
    }```

````

result :

````auto

[
  {
    "TERMINAL_NO": 13,
    "day": 2,
    "month": 12,
    "year": 22,
    "hour": 11,
    "minute": 59,
    "second": 59,
    "CARD_NUMBER": 1115481172,
    "Event1": 11,
    "Event2": 0,
    "Event3": 0,
    "Event4": 0,
    "Event5": 0,
    "Event6": 0
  }
]```

````

---

<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 2, 2023, 1:10pm UTC](https://discuss.elastic.co/t/how-to-special-date-time-format-to-timestamp-format/320444/8 "2023-01-02T13:10:09Z")

</div>

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