# Get year month and day from date field

**URL:** <https://discuss.elastic.co/t/get-year-month-and-day-from-date-field/110600>\
**Category:** Logstash\
**Created:** [December 7, 2017, 3:38am UTC](https://discuss.elastic.co/t/get-year-month-and-day-from-date-field/110600 "2017-12-07T03:38:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)\
**Post date:** [December 7, 2017, 3:38am UTC](https://discuss.elastic.co/t/get-year-month-and-day-from-date-field/110600/1 "2017-12-07T03:38:55Z")

</div>

hi  
my csv data -  
`"s1","salesman01","2017-06-22 00:00:00.000","2017-06-22 16:10:23.000","2017-06-22 16:11:44.000","5","25.252130,55.349060"`  
i want to create new field which will call computeid for that i used this -  
`mutate { add_field => { "salesid" => "%{SalesmanCode} %{VisitDate}" } }`

result is - "s4 2017-06-22T12:00:00.000Z"  
but i want data in this format -\> "s420170622" means year ,month and day from visit date  
how can i get that ,any suggestion .  
thanks

---

<div class="post-metadata">

**Author:** ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)\
**Post date:** [December 7, 2017, 4:40am UTC](https://discuss.elastic.co/t/get-year-month-and-day-from-date-field/110600/2 "2017-12-07T04:40:22Z")

</div>

ok i got it working

```
 grok {
    match => { "VisitDate" => "(?<dateid>[0-9]{4}\-[0-9]{2}\-[0-9]{2})"}
  }
  
  grok {
  match => { "VisitDate" => "(?<indexid>[0-9]{4}\-[0-9]{2})"}
}

    
  
  mutate {
  gsub => ["dateid","-",""]
  gsub => ["indexid","-",""]
  
  add_field => { "[@metadata][indexid]" => "%{indexid}" }
  add_field => {
    "salesid" => "%{SalesmanCode}%{dateid}"
  }
   remove_field => ["dateid","indexid"]
}

```

if there is any other way , so am happy to learn .

---

<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 4, 2018, 4:45am UTC](https://discuss.elastic.co/t/get-year-month-and-day-from-date-field/110600/3 "2018-01-04T04:45:55Z")

</div>

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