# Parsing Different Date Format From File Name

**URL:** <https://discuss.elastic.co/t/parsing-different-date-format-from-file-name/157518>\
**Category:** Logstash\
**Created:** [November 20, 2018, 10:49am UTC](https://discuss.elastic.co/t/parsing-different-date-format-from-file-name/157518 "2018-11-20T10:49:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![goutamdas](https://avatars.discourse-cdn.com/v4/letter/g/e99b99/32.png) [@goutamdas](https://discuss.elastic.co/u/goutamdas)\
**Post date:** [November 20, 2018, 10:49am UTC](https://discuss.elastic.co/t/parsing-different-date-format-from-file-name/157518/1 "2018-11-20T10:49:33Z")

</div>

Hi all,

I have a requirement where there are no date getting captured in the logs, whereas time has been captured. But the log file name has date + time in it. And there are different types of file name.

For ex. I have a file one type: XXXX\_ZZZZZZZZ\_TTTTTT\_11062018151447664.log

If you look at the number string:  
First 2 digit is Day  
3rd and 4th digit is month  
5th, 6th, 7th and 8th digit is year  
and, subsequently hh:mm:ss:SSS

2nd type of file: XXXXXX.ZZZZ.2018.06.11.14.59.28.log

If you look at the number string:  
First 4 digit is Year  
Next 2 digit is month  
Next 2 digit is day

Now, what I want to do is, I want to parse both of the file name format in the grok script and extract as YYYY-MM-dd HH:mm:ss.SSS for the 1st file type, and,  
YYYY-MM-dd HH:mm:ss for the 2nd file type...

can any one help please?

Regards,  
Goutam

---

<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:** [December 18, 2018, 10:56am UTC](https://discuss.elastic.co/t/parsing-different-date-format-from-file-name/157518/2 "2018-12-18T10:56:30Z")

</div>

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