# How to set a value in timestamp

**URL:** https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762
**Category:** Logstash
**Created:** [January 23, 2023, 8:26pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762 "2023-01-23T20:26:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mariana17](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mariana17](https://discuss.elastic.co/u/mariana17)
#### Post date: [January 23, 2023, 8:26pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/1 "2023-01-23T20:26:47Z")

</div>

I have two values as my date and hour data and i want them to be my timestamp:

"F-MESSAGE-CAB": "20221018","H-MESSAGE-CAB": "601006"  
"F-MESSAGE-CAB": "20221018","H-MESSAGE-CAB": "1338311"

What i'm trying to do is putting them together into one value and then overwrite the timestamp value but it doesn't work, i had tried with different date formats but the timestamp doesn't change from the actual date

This is the code

```auto
	mutate{
		add_field => {
			"DATE" => "%{F-MESSAGE-CAB}%{H-MESSAGE-CAB}" 
		}
	}
	date{
		match => ["DATE", "yyyy-MM-dd h:mm:ss"]
		target => "@timestamp"
	}

}

```

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [January 23, 2023, 8:45pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/2 "2023-01-23T20:45:53Z")

</div>

> [@mariana17](#):
>
> "H-MESSAGE-CAB": "1338311"

What does that number represent?

---

<div class="post-metadata">

### Author: ![mariana17](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mariana17](https://discuss.elastic.co/u/mariana17)
#### Post date: [January 23, 2023, 8:49pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/3 "2023-01-23T20:49:05Z")

</div>

It's the hour "1338311" as 13:38:311

---

<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: [January 23, 2023, 8:58pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/4 "2023-01-23T20:58:06Z")

</div>

Try this:

> [@mariana17](#):
>
> ```
> add_field => {
> "DATE" => "%{F-MESSAGE-CAB} %{H-MESSAGE-CAB}" # with space
> }
> 
> ```
> 
> `match => ["DATE", "yyyyMMdd Hmmsss"]`

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [January 23, 2023, 11:14pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/5 "2023-01-23T23:14:01Z")

</div>

> [@mariana17](#):
>
> 13:38:311

Is that 311 seconds, or 31.1?

---

<div class="post-metadata">

### Author: ![mariana17](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mariana17](https://discuss.elastic.co/u/mariana17)
#### Post date: [January 24, 2023, 2:45pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/6 "2023-01-24T14:45:04Z")

</div>

31.1 seconds

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [January 24, 2023, 5:22pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/7 "2023-01-24T17:22:13Z")

</div>

```
    ruby { code => 'event.set("H-MESSAGE-CAB", event.get("H-MESSAGE-CAB").to_s.rjust(7, "0"))' }
    mutate { add_field => { "[@metadata][date]" => "%{F-MESSAGE-CAB} %{H-MESSAGE-CAB}" } }
    date{ match => ["[@metadata][date]", "yyyyMMdd HHmmssS"] }

```

will produce

```
{
"H-MESSAGE-CAB" => "0601006",
"F-MESSAGE-CAB" => "20221018", 
   "@timestamp" => 2022-10-18T10:01:00.600Z, ...
}
{
"H-MESSAGE-CAB" => "1338311",
"F-MESSAGE-CAB" => "20221018",
   "@timestamp" => 2022-10-18T17:38:31.100Z, ...

```

---

<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 21, 2023, 5:22pm UTC](https://discuss.elastic.co/t/how-to-set-a-value-in-timestamp/323762/8 "2023-02-21T17:22:37Z")

</div>

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