# Get today's date that change automatically everyday

**URL:** https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934
**Category:** Logstash
**Created:** [May 11, 2020, 6:29am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934 "2020-05-11T06:29:20Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)
#### Post date: [May 11, 2020, 6:29am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/1 "2020-05-11T06:29:21Z")

</div>

I am trying to add a new field, "Today's Date" to get the Today's/Current date from logstash into elasticsearch.

Here is my configuration in logstash

```auto
input {
  file {
    path => "C:/Users/Admin/Documents/dummy_test_date.csv"
    start_position => "beginning"
    sincedb_path => "NUL"
  }
}
filter {
  	csv {
    	separator => ","
    	columns => ["ID","Challenge Statements","Test Cases","Start Date","End Date]
    	
    	add_field => {
    		"Today's Date" => "%{+dd/MM/yyyy}"	 
    	}
  	}

  	date {
        match => ["Today's Date", "dd/MM/yyyy"]
        target => "Today's Date"
        timezone => "Asia/Kuala_Lumpur"
      }

	date {
    	match => ["Start Date", "dd/MM/yyyy"]
    	target => "Start Date"
    	timezone => "Asia/Kuala_Lumpur"
 	}

 	date {
    	match => ["End Date", "dd/MM/yyyy"]
    	target => "End Date"
    	timezone => "Asia/Kuala_Lumpur"
  	}

}

output {
   elasticsearch {
     hosts => "http://127.0.0.1:9200"
     index => ["dummydata-1"]
     document_id => "%{[ID]}"
     user => "elastic"
     password => "password"
  }
stdout {}
}

```

However with this configuration, the date in "Today's Date" field did not change automatically to the next day date in elasticsearch & kibana.

Would appreciate anyone could tell me what I am doing wrong in this config? Thank you!

---

<div class="post-metadata">

### Author: ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)
#### Post date: [May 12, 2020, 12:38am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/2 "2020-05-12T00:38:24Z")

</div>

Anyone?

---

<div class="post-metadata">

### Author: ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)
#### Post date: [May 12, 2020, 12:56am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/3 "2020-05-12T00:56:35Z")

</div>

if you're passing today's date, why would you expect next day's date?

also elastic shows @timestamp in UTC. since you're on UTC+8 date, is it possible that you're looking at UTC timestamp?

---

<div class="post-metadata">

### Author: ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)
#### Post date: [May 12, 2020, 1:19am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/4 "2020-05-12T01:19:37Z")

</div>

Thanks for the reply @ptamba! I am tracking a project progress based on the start date, end date and the current date. Hence, I want the current date to change automatically to Today's/Current date in Elasticsearch.

`Something like date.now is JavaScript or =Today() in Microsoft excel `

---

<div class="post-metadata">

### Author: ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)
#### Post date: [May 12, 2020, 1:38am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/5 "2020-05-12T01:38:48Z")

</div>

> [@yummycake](#):
>
> add\_field =\> { "Today's Date" =\> "%{+dd/MM/yyyy}" }

this code here add a new field called "Today's Date" into your document before sending to elasticsearch. I'm not sure what else is it that you expect.

---

<div class="post-metadata">

### Author: ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)
#### Post date: [May 12, 2020, 1:55am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/6 "2020-05-12T01:55:38Z")

</div>

> [@yummycake](#):
>
> add\_field =\> { "Today's Date" =\> "%{+dd/MM/yyyy}" }

Yes, you are right about this. However, this code only takes today's date.

For example, if I import my CSV file from logstash to elasticsearch today, in elasticsearch it will show today's date. But if I open up elasticsearch tomorrow, this code does not change to tomorrow's date, it will still give today's date instead.

Thus, I want the date to change to the current date as the day goes if this makes sense?

Apologies for the confusion.

---

<div class="post-metadata">

### Author: ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)
#### Post date: [May 12, 2020, 2:07am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/7 "2020-05-12T02:07:47Z")

</div>

so you want to modify the value of existing document stored in elasticsearch? elasticsearch topic would be a better forum to ask about it.

you could do it in logstash with elasticsearch filter. basically you search for documents that has “Today’s date” field then update the “Today’s date” value using current date value. you can run it with a daily cron at the start of day.

---

<div class="post-metadata">

### Author: ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)
#### Post date: [May 12, 2020, 2:47am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/8 "2020-05-12T02:47:57Z")

</div>

> [@ptamba](#):
>
> so you want to modify the value of existing document stored in elasticsearch? elasticsearch topic would be a better forum to ask about it.

Sure, I will ask this in Elasticsearch topic instead.

> [@ptamba](#):
>
> you could do it in logstash with elasticsearch filter. basically you search for documents that have “Today’s date” field then update the “Today’s date” value using current date value. you can run it with a daily cron at the start of the day.

Do you think I could create a ruby filter in logstash to achieve this? Nonetheless, I will definitely try the given options. Thank you!

---

<div class="post-metadata">

### Author: ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)
#### Post date: [May 12, 2020, 3:02am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/9 "2020-05-12T03:02:15Z")

</div>

> [@yummycake](#):
>
> Do you think I could create a ruby filter in logstash to achieve this? Nonetheless, I will definitely try the given options. Thank you!

doing it with ruby filter will achieve the same result.  
from what you're saying, you're trying to modify existing documents that are already stored within elasticsearch.

---

<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: [June 9, 2020, 3:02am UTC](https://discuss.elastic.co/t/get-todays-date-that-change-automatically-everyday/231934/10 "2020-06-09T03:02:20Z")

</div>

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