# Timestamp from filename

**URL:** https://discuss.elastic.co/t/timestamp-from-filename/154938
**Category:** Logstash
**Created:** [October 31, 2018, 10:44pm UTC](https://discuss.elastic.co/t/timestamp-from-filename/154938 "2018-10-31T22:44:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SusantaBN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/susantabn/32/37273_2.png) [@SusantaBN](https://discuss.elastic.co/u/SusantaBN)
#### Post date: [October 31, 2018, 10:44pm UTC](https://discuss.elastic.co/t/timestamp-from-filename/154938/1 "2018-10-31T22:44:58Z")

</div>

I have a requirement to put the timestamp on log file name and subsequently extract the timestamp from filename and add as a field in the elastic search index.

e.g. file name: 2018-10-31\_13-11-25.33.csv

**My custom grok**

SUS\_DATE %{YEAR}-%{MONTHNUM}-%{MONTHDAY}\_%{HOUR}-%{MINUTE}-%{SECOND}

**Conf file contents**  
input{  
file{  
path =\>"D:/ELK\_Stack/data/DLS/HM/\*.csv"  
start\_position =\>"beginning"  
}  
}  
filter{  
grok {  
patterns\_dir =\> "./patterns"  
match =\> ["path","D:/ELK\_Stack/data/%{DATA:srvtyp}/%{DATA:srvloc}/%{SUS\_DATE:dattim}.csv"]  
}  
date {  
match =\> ["dattim","YYYY-MM-dd\_HH-mm-ss.SS"]  
}

But I always get dattim in type text instead of date.

![Capture](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1b391554fe35c97c88acda24528742783a58f02f.png)

I work on windows OS. Any help to convert dattim to type DATE would be highly appreciated.

---

<div class="post-metadata">

### Author: ![tamara](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tamara/32/47095_2.png) [@tamara](https://discuss.elastic.co/u/tamara)
#### Post date: [October 31, 2018, 11:08pm UTC](https://discuss.elastic.co/t/timestamp-from-filename/154938/2 "2018-10-31T23:08:45Z")

</div>

You have the wrong date format change the date filter from:

`match => ["dattim","YYYY-MM-dd_HH-mm-ss.SS"]`

to

`match => ["dattim","yyyy-MM-dd_HH-mm-ss.SS"]`

---

<div class="post-metadata">

### Author: ![SusantaBN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/susantabn/32/37273_2.png) [@SusantaBN](https://discuss.elastic.co/u/SusantaBN)
#### Post date: [November 1, 2018, 7:58pm UTC](https://discuss.elastic.co/t/timestamp-from-filename/154938/3 "2018-11-01T19:58:18Z")

</div>

Thanks a lot Tamara. Solution worked well.

---

<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: [November 29, 2018, 7:58pm UTC](https://discuss.elastic.co/t/timestamp-from-filename/154938/4 "2018-11-29T19:58:26Z")

</div>

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